【发布时间】:2021-03-26 02:43:38
【问题描述】:
这是我的图表的样子: https://i.stack.imgur.com/PnDt6.png
我需要在工具提示中以时间格式显示值,例如 00:55:25。 此图表需要绘制不同天文台的时间。
这是我的代码。
var ctx = document.getElementById("myBarChart");
var myLineChart = new Chart(ctx, {
type: 'bar',
data: {
labels: ['activity 1', 'activity 2', 'activity 3'],
datasets: [{
label: "Value",
backgroundColor: "rgba(2,117,216,1)",
borderColor: "rgba(2,117,216,1)",
data: [545, 3600, 3211],
}],
},
options: {
scales: {
xAxes: [{
time: {
unit: 'month'
},
gridLines: {
display: false
},
ticks: {
maxTicksLimit: 3
}
}],
yAxes: [{
ticks: {
min: 0,
max: 36000,
stepSize: 3600,
beginAtZero: true,
callback: function (label, index, labels) {
console.log(label)
switch (label) {
case 3600:
return '01:00:00';
case 7200:
return '02:00:00';
case 10800:
return '03:00:00';
case 14400:
return '04:00:00';
case 18000:
return '05:00:00';
case 21600:
return '06:00:00';
case 25200:
return '07:00:00';
case 28800:
return '08:00:00';
}
}
},
}],
},
legend: {
display: false
}
}
});
如何将数据集中的值更改为时间格式或仅在视图中?
【问题讨论】:
标签: javascript charts chart.js bar-chart