artus9033 / chartjs-plugin-dragdata

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

Can we store the value after dragging? #48

Closed icezerowjj closed 4 years ago

icezerowjj commented 4 years ago

This is such great work!

But I am just wondering if it is able to return the value of the points after the user makes the tweak on the graph.

Thanks

cmsImagine commented 4 years ago

The onDragEnd callback passes the new value of what was dragged as the 4th parameter:


    onDragEnd: function (e, datasetIndex, index, value) {

    }
icezerowjj commented 4 years ago

The onDragEnd callback passes the new value of what was dragged as the 4th parameter:


    onDragEnd: function (e, datasetIndex, index, value) {

    }

Thanks! But I am using this thing in React JS. I will need to define a similar function in JSX I assume?

chrispahm commented 4 years ago

Well here's a working example in React: https://jsfiddle.net/ecb4rz5v/

In the chart options, right where you defined dragData: true, you also define the onDragEnd callback. Check out the example and observe the logs to the console after dragging a point.

icezerowjj commented 4 years ago

Well here's a working example in React: https://jsfiddle.net/ecb4rz5v/

In the chart options, right where you defined dragData: true, you also define the onDragEnd callback. Check out the example and observe the logs to the console after dragging a point.

Yeah, this is so amazing and I am exactly referring to this example here. I will figure that out myself and I do appreciate it.

Here's probably my last question as I didn't see the answer online yet. If my labels are not even like they go from values such as 1, 2, 3, 6, 12, 24, 48, 120 (months)... How should I adjust the intervals of them on the XAxes, please?

chrispahm commented 4 years ago

Hmm so you want to change the axis tick intervals? If so, here's a guide on how to do that: https://stackoverflow.com/questions/53523600/how-to-change-x-axis-interval-on-chart-js

icezerowjj commented 4 years ago

Hmm so you want to change the axis tick intervals? If so, here's a guide on how to do that: https://stackoverflow.com/questions/53523600/how-to-change-x-axis-interval-on-chart-js

Thank you very much. This is really helpful!

chrispahm commented 4 years ago

Alright I will close this as resolved then!