在 Chart.js 中将 Y 轴值从实数更改为整数 [英] Change the Y-axis values from real numbers to integers in Chart.js

查看:24
本文介绍了在 Chart.js 中将 Y 轴值从实数更改为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图表,我想使用

这是代码:

var lineChartData = {标签:[2013/04/01"、2013/03/31"、2013/03/30"、2013/03/29"、2013/03/28"、2013/03/27", "2013/03/26"],数据集:[{fillColor : "rgba(151,187,205,0.5)",strokeColor : "rgba(151,187,205,1)",pointColor : "rgba(151,187,205,1)",pointStrokeColor : "#fff",数据:[0"、2"、1"、0"、1"、0"、1"]}]}var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(lineChartData);

解决方案

试试这个,其中 max 是数据的最大值.

var 步骤 = 3;新图表(ctx).Bar(plotData, {规模覆盖:真,scaleSteps:步骤,scaleStepWidth: Math.ceil(max/steps),规模开始值:0});

I have a chart that I want to include in my website using Chart.js. In the Y-axis, it gives me real numbers instead of integers. How can I change the number to integers?

Here's a picture of what I have now:

And this is the code:

var lineChartData = {

    labels : ["2013/04/01","2013/03/31", "2013/03/30", "2013/03/29", "2013/03/28","2013/03/27", "2013/03/26"],

    datasets : [
        {
            fillColor : "rgba(151,187,205,0.5)",
            strokeColor : "rgba(151,187,205,1)",
            pointColor : "rgba(151,187,205,1)",
            pointStrokeColor : "#fff",
            data : ["0", "2","1", "0", "1","0","1"]
        }
    ]

}

var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(lineChartData);

解决方案

Try this, where max is the highest value of your data.

var steps = 3;
new Chart(ctx).Bar(plotData, {
    scaleOverride: true,
    scaleSteps: steps,
    scaleStepWidth: Math.ceil(max / steps),
    scaleStartValue: 0
});

这篇关于在 Chart.js 中将 Y 轴值从实数更改为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆