Ideally what I'd like to achieve is something like this D3.js chart, where the time scale, if it spans multiple months and autoskips dates, adds the months or even years underneath the dates at the corresponding location. This looks a lot less cluttered than repeating the month and/or year with every date.
Current Behavior
A multiline date is not supported in Chart.js
Possible Solution
I tried to replicate this behavior instead on the same line via the afterTickToLabelConversionfunction.
There I would only return the actual day for a tick, unless it's a new month, where the month gets prepended:
One challenge there is that with a longer date range and autoskipping active, the first of the month is not necessarily going to be plotted. It might be that the 3rd or 5th of the month is the actual date that shows up. In order to know when the first drawn date of a month is, I need to know the skipRatio. Unfortunately, the scaleInstance that gets passed into it, does not contain that. So I calculated it based on the original formula.
However, I noticed that the more the date range was increased, the calculated skipRatiodid not actually match the dots drawn. It seems to be related to the Math.floor part, where the actual skipRatiocould result in something like 6.9 which Math.floor rounds down to 6 while the dots where spaced 7 apart. Changing this to Math.round instead in both the source and in my afterTickToLabelConversion function seemed to solve the issue. So my codepen contains the modified Chart.js on top, example code at the bottom.
Change Start Date back month by month and see the time scale properly update
Once you hit January, time scale is skipping months
(Side note: while stepping through the months, you will notice that December sometimes goes missing and that seems to be related to this already existing bug.)
Context
Now, I thought I solved this issue by changing Math.floor to Math.round, but once I navigate back almost a year to January, the proper labeling stops working and I'm not exactly sure why that is. Any suggestions if this could be solved differently would be appreciated. Thanks!
Environment
Chart.js version: > 2.3.0
Browser name and version: macOS Version 10.10.5 / Chrome Version 54.0.2840.98 (64-bit)
Expected Behavior
Ideally what I'd like to achieve is something like this D3.js chart, where the time scale, if it spans multiple months and autoskips dates, adds the months or even years underneath the dates at the corresponding location. This looks a lot less cluttered than repeating the month and/or year with every date.
Current Behavior
A multiline date is not supported in Chart.js
Possible Solution
I tried to replicate this behavior instead on the same line via the
afterTickToLabelConversion
function. There I would only return the actual day for a tick, unless it's a new month, where the month gets prepended: One challenge there is that with a longer date range and autoskipping active, the first of the month is not necessarily going to be plotted. It might be that the 3rd or 5th of the month is the actual date that shows up. In order to know when the first drawn date of a month is, I need to know the skipRatio. Unfortunately, thescaleInstance
that gets passed into it, does not contain that. So I calculated it based on the original formula.However, I noticed that the more the date range was increased, the calculated
skipRatio
did not actually match the dots drawn. It seems to be related to theMath.floor
part, where the actualskipRatio
could result in something like6.9
whichMath.floor
rounds down to6
while the dots where spaced7
apart. Changing this toMath.round
instead in both the source and in myafterTickToLabelConversion
function seemed to solve the issue. So my codepen contains the modified Chart.js on top, example code at the bottom.Steps to Reproduce (for bugs)
(Side note: while stepping through the months, you will notice that December sometimes goes missing and that seems to be related to this already existing bug.)
Context
Now, I thought I solved this issue by changing
Math.floor
toMath.round
, but once I navigate back almost a year to January, the proper labeling stops working and I'm not exactly sure why that is. Any suggestions if this could be solved differently would be appreciated. Thanks!Environment