javascript - 我怎样才能只显示整数标签?
问题描述
我的图表有 100 个标签。这些标签是从 0 到 10。有些标签是十进制的。但我只想在我的图表上看到整数。我怎样才能隐藏小数?您可以在下面查看我的图片和代码。
var timeLabels = [];
for (let j = 0; j <= scheduling.totalPeriod; j++) {
timeLabels.push(j / 10);
}
var schedulingChart = new Chart(ctx, {
type: 'line',
data: {
labels: timeLabels,
datasets: [{
steppedLine: true,
label: scheduling.process[i].name,
data: scheduling.process[i].chart,
backgroundColor: ['rgba(255, 255, 255, 0.5)'],
borderColor: ['rgba(255, 255, 255, 1)'],
borderWidth: 1,
pointBackgroundColor: 'green',
pointBorderColor: 'black',
pointRadius: 4
}]
},
options: {
maintainAspectRatio: false,
scales: {
yAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0.5)',
},
ticks: {
stepSize: 1,
fontColor: 'rgba(255, 255, 255, 1)'
}
}],
xAxes: [{
gridLines: {
color: 'rgba(0, 0, 0, 0.5)',
},
ticks: {
fontColor: 'white',
}
}]
}
}
});
解决方案
推荐阅读
- ruby-on-rails - Rails 生成失败
- reactjs - 根据antd表中的数据默认选择表行
- javascript - Javascript 参考 vs 值 - 数组
- google-maps - 有没有办法完全限制企业(机构)出现在自动完成中?
- go - 如果您不能为函数指针赋值,那么 Go 中的函数指针有什么用?
- mongodb - 语法缺失;在mongoexport中声明之前
- swift - 如何从另一个 ViewController 更改标签颜色?迅速
- jquery - 每次无法验证单个选项卡
- java - 完整设置后运行方法
- kentico-kontent - `published` / `unpublished` webhook 在内容可用之前发送