简体   繁体   中英

Changing x axis labels in Chart.js line chart

Is it possible to set custom x axis labels in Chart.js? Currently I'm using my array of indexes but is is hard to read anything on this chart, so I would like to scale it and show only specified indexes. For example: instead [1,2,3,4,5,6,7,8,9,10], I would like to set [1,5,10]

With Chart.js you can't override the horizontal axis labels. Its a great library, sad it doesn't support this.

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

For example, if you just want to show the x axis label every 10 points, you can do something like this when generating the labels:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM