Changing the x-axis labels in a line chart Chart.js

Can I set custom X axis labels in Chart.js? I am currently using my array of indices, but it is difficult to read anything on this graph, so I would like to scale it and show only the indicated indices. For example: instead of [1,2,3,4,5,6,7,8,9,10], I would like to set [1,5,10]

+6
source share
1 answer

With Chart.js, you cannot redefine horizontal axis labels. Its a great library, sad that it does not support.

The easiest way to do this without getting into the Chart.js code and without redrawing the canvas is to leave the label cell with an empty line.

For example, if you just want to show the x-axis label every 10 points, you can do something similar when creating labels:

if (ix % 10 == 0) { labels[ix]="Label"; } else { labels[ix]=""; } 
+7
source

All Articles