如何在chartjs中将Y轴值从实数改为整数? [英] how to change the Y-axis values from real numbers to integer in chartjs?

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

问题描述

我有一个图表,我想使用 Chart.js 加入我的网站。在Y轴,它给了我真正的数字,而不是整数,这就是我想要的,这是一个我现在的照片:

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, and that's what I want, here's a picture of what i have now:

这是代码:

    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);


推荐答案

尝试这个,其中max是数据。

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
});

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

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