我一直在使用 chartjs 制作图表,显示每天的锻炼持续时间。所以 x 轴有日期,y 轴有持续时间,数据集的值最大持续时间为 1.30,最小值为 0.00。我想要y 轴显示标签,如 0.00、0.10、0.20...、1.20、1.30。
我可以显示标签为 .1、.2 ... 1.3 的图表。代码如下。
我可以显示标签为 .1、.2 ..1.3 的图表。代码如下。
var options = {
type: 'line',
data: {
labels: newDates.split(','),datasets: [{
label: 'Time',
data: newDuration.split(','),
borderWidth: 1,
fill: false,
borderColor: "#fff"
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: true,
},
legend: {
display: false
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
suggestedMax: 1.30,
stepSize: .10,
fontColor: 'rgba(255, 255, 255)' // makes grid lines from y axis red
},
gridLines: {
color: 'rgba(255, 255, 255, 0.2)' // makes grid lines from y axis red
}
}],
xAxes: [{
ticks: {
beginAtZero: true,
fontColor: 'rgba(255, 255, 255)' // makes grid lines from y axis red
},
gridLines: {
display:false
}
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
预期结果:
y 轴显示标签为 0 0.10 0.20 0.30 ... 1.20,1.30
最佳答案
改变这个
yAxes: [{
ticks: {
precision: 2
}
}],
关于javascript - Chart JS Y轴标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54396386/