chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.8k stars 11.92k forks source link

Wrong position ticks in time scale with offsetGridLines #5490

Open alexandre-tobia opened 6 years ago

alexandre-tobia commented 6 years ago

Hi,

I'm using chartjs latest version (2.7.2).

I'm using offsetGridLines: true to center my xAxes label (2016, 2017,...), but since i use this options, my points are not in the right position.

For example, this point need to be between the red lines (because it belongs to 2016)

Image of Yaktocat

jsfidle: https://jsfiddle.net/mrbmvd19/1/ (look at the 2016-12-01)

Do you know how to do that?

Thanks a lot.

etimberg commented 6 years ago

@alexandre-tobia offsetGridLines also centers the values, so 2017 starts at the 2017 label.

@simonbrunel thoughts on a way to improve this?

alexandre-tobia commented 6 years ago

@etimberg unfortunately yes...

so, in this case, the vertical line become totally useless (and meaningless ), maybe an option to avoid values to be automaticaly centered ?

ahukkanen commented 5 years ago

This was also confusing me. Investigating further...

ahukkanen commented 5 years ago

Got this working so that at least when I'm using the time scale for years, it splits the years with the grid lines and prints the year label in the middle of the year.

Here's an example that has been tested with Chart.js v2.7.3: https://gist.github.com/ahukkanen/fe69a70c3708b32210fd18860ba609c5

ahukkanen commented 5 years ago

Is this a bug by the way or intended behavior? This was totally confusing to me at first before I found this issue.

kurkle commented 3 years ago

Does not look like an issue in v3 anymore?: https://jsfiddle.net/n5dbt2ue/ Could be actually fixed in 2.9 already, did not test.

Edit: nevermind image