最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Changing x axis labels in Chart.js line chart - Stack Overflow

programmeradmin6浏览0评论

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]

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]

Share Improve this question edited Mar 31, 2014 at 11:06 R3tep 12.9k10 gold badges51 silver badges76 bronze badges asked Mar 31, 2014 at 10:54 NataliaNatalia 691 silver badge4 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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]="";
    }
发布评论

评论列表(0)

  1. 暂无评论