Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

beginAtZero ignored in line-chart

Open stephanarts opened this issue 11 years ago • 8 comments

I want to use Chart.js to draw a time-line graph of values that can not have a negative value. - Think about CPU-load (floating-point value between 0.0 and a lot), network-throughput (bytes/s).

The timescale graph in Chart.js 2.0 appears to be a good fit, but it looks weird if the base-line is drawn at the center of the graph. (which happens if you draw a lot of values between 0.08 and 0.2).

I get the impression that beginAtZero is ignored in the line-chart.

stephanarts avatar Oct 27 '15 20:10 stephanarts

@stephanarts beginAtZero should work, though the config has changed since V1. Here's a JSBin with the beginAtZero option. You can try changing it and seeing the effect.

etimberg avatar Oct 27 '15 21:10 etimberg

@etimberg I see what you mean, I was aware of the config-change and it does work. - sometimes. It appears to be related to the x or y values assigned to the dataset.

If I assign the values hard-coded as strings in my js file, it works. If I retrieve them as a JSON object from an AJAX call it doesn't work. Let me check where the difference is coming from.

stephanarts avatar Oct 27 '15 21:10 stephanarts

I am clueless as to why it didn't work earlier... I must have done something terribly wrong.

@etimberg: thank you for confirming the location of the beginAtZero option in v2.0 :-)

stephanarts avatar Oct 27 '15 22:10 stephanarts

@stephanarts glad its fixed. Let me know if you see it again and I'll give it a stress test.

etimberg avatar Oct 27 '15 22:10 etimberg

@etimberg I managed to reproduce it here: http://jsbin.com/dusesimiqa

stephanarts avatar Oct 27 '15 22:10 stephanarts

I see the issue. The relevant lines are: https://github.com/nnnick/Chart.js/blob/v2.0-dev/src/scales/scale.linear.js#L103-L106

etimberg avatar Oct 27 '15 23:10 etimberg

@stephanarts a fix is in #1581

etimberg avatar Oct 28 '15 00:10 etimberg

Confirmed.

stephanarts avatar Nov 01 '15 11:11 stephanarts