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

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

问题描述

我想要使用



这是代码:

  var lineChartData = {

labels:[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:#ffff,
数据:[0,2,1,0,1,0,1]
}
]

}

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


解决方案

试试这个,其中max是你的最高价值数据。

  var steps = 3; 
new Chart(ctx).Bar(plotData,{
scaleOverride:true,
scaleSteps:steps,
scaleStepWidth:Math.ceil(max / steps),
scaleStartValue: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天全站免登陆