【发布时间】:2021-09-24 18:05:28
【问题描述】:
我想创建带有滚动时间的实时图表,例如以下视频:https://www.youtube.com/watch?v=2-tnkzG0sKU
chart.js 可以做到这一点吗?到目前为止,我有以下内容,它正在滚动但时间没有显示,我想以秒为单位显示。
let dataSize = 500;
let readings = new Array(dataSize);
// data object for the chart:
const data = {
// X axis labels
labels: new Array(),
datasets: [{
data: readings, // the data to chart
borderColor: '#272323', // line color (lavender)
pointRadius: 0.5 // point size
}]
};
const config = {
type: 'line', // type of chart
data: data, // the data
options: {
animation: false, // remove animation to speed drawing up
responsive: true,
maintainAspectRatio: false,
scales: { // axis ranges:
y: {
type: 'linear',
min: 0,
max: 255
},
x:{
// ticks:{
type: 'time',
time:{
//unit:'second',
displayFormats: {hour: 'mm:ss'}
},
min:0,
max: dataSize,
//beginAtZero: true,
maxTicksLimit: dataSize/2
//}
}
}
}
};
谢谢
【问题讨论】:
标签: javascript chart.js