artus9033 / chartjs-plugin-dragdata

Draggable data points plugin for Chart.js
MIT License
257 stars 55 forks source link

returning false for onDrag only works once #110

Closed louis1999 closed 1 year ago

louis1999 commented 1 year ago

Hello,

I'm on reactjs using chartjs-plugin-dragdata.

I have a Line graph with drag data on it, i want to fix the first point of my graph to x=0 and y is dragable. So, i return false in onDrag if the index===0 and value.x!==0 That's working correctly the first time i try to move the point but if i try again, the point can be moved

Any idea how to solve that ?

Additional question : Is it possible the put onDragX:false for certain value ?

chrispahm commented 1 year ago

Hey @louis1999, did you get it to work?

louis1999 commented 1 year ago

Yes and no. Indeed, my explanation was wrong. The reason the first try was going back at it"s initial place was an error (on my side). That's why i closed the discussion. I fixed that problem (each time i was adding a data point to the chart, the next time i was trying to move that point, it wasn't moving).

Now that is fixed, i will soon try again the conditions on the x axis, most probably on in onDrag but in on dragEn if it's easier.

I would add a quick question where you might help me but it's quite specific. Using chartjs in reactjs, if my data points are stored in a state and i change that state outside the chart options (if a add a point for example), the updated state can't be accessible in the chart options (so not accessible in onDrag and onDragEnd). I found on internet that a solution was to use references. That solution works quite well even if that duplicates a lot of code. For what reason is the state not updating in the chart options and are there other solutions to fix that problem ?