artus9033 / chartjs-plugin-dragdata

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

Floating point number with stacked bars #31

Closed josh-s-g closed 5 years ago

josh-s-g commented 5 years ago

Firstly, what a great library, thanks! I'm having some trouble with a stacked bar chart with all-but-one of the series having value 0 (this is so I can have multiple data labels to draw the ˅˄). I've set

dragData: false

for the series with value 0, but sometimes when dragging the remaining visible bar section, I get a lot of decimal places in the value: lots_of_decimals

I have set

dragDataRound: 1,

Am I doing something wrong here? Or is it a likely to be an interaction with the multiple datasets and labels?

chrispahm commented 5 years ago

Hey there! That chart looks beautiful with these little arrows! Very nice way of suggesting that the chart can be interacted with :) This look like a bug to me... However, without your particular setup I cannot reproduce it. Would you be willing to share a jsFiddle/Plunker/HTML file so I can have a look?

Best Christoph

josh-s-g commented 5 years ago

Thank you! I'll see if I can find 5 mins to stick it in a jsFiddle, but in the meantime could it be something to do with https://github.com/chrispahm/chartjs-plugin-dragdata/blob/master/src/index.js#L126 ?

calcPosition does some rounding, but looks like cursorPos - initValue isn't rounded (based on a 2-minute check, so I might be wrong!).

Thanks

chrispahm commented 5 years ago

Well yes, that may be true! I just made a new branch called rounding, where the line that you are referencing is rounded as well. You can test the branch by using this file: https://chrispahm.github.io/chartjs-plugin-dragdata/assets/chartjs-plugin-dragdata.min.js

josh-s-g commented 5 years ago

Yes, that looks to have fixed it! Thanks :+1: