gpt4 book ai didi

javascript - 在 Chart.js 中将 Y 轴值从实数更改为整数

转载 作者:IT王子 更新时间:2023-10-29 02:59:13 24 4
gpt4 key购买 nike

我有一个图表,我想使用 Chart.js 将其包含在我的网站中.在 Y 轴上,它给了我实数而不是整数。如何将数字更改为整数?

这是我现在拥有的图片:

current chart with real numbers

这是代码:

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

最佳答案

我在新版本中是这样处理的:

new Chart(ctx, {
type: 'bar',
data: chartData,
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
callback: function(value) {if (value % 1 === 0) {return value;}}
}
}]
}
}
});

关于javascript - 在 Chart.js 中将 Y 轴值从实数更改为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15751571/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com