Chart.js chartjs:未捕获异常:0和X相距太远,步长为Y
我正在用chartjs在图形上绘制数据。它过去是有效的,但我不知道为什么我不断地得到未捕获的异常:0和1587533402000的距离太远,步长为1小时,尽管0和1587533402000都不是我绘制的数据的一部分 以下是我绘制图表的方式:Chart.js chartjs:未捕获异常:0和X相距太远,步长为Y,chart.js,Chart.js,我正在用chartjs在图形上绘制数据。它过去是有效的,但我不知道为什么我不断地得到未捕获的异常:0和1587533402000的距离太远,步长为1小时,尽管0和1587533402000都不是我绘制的数据的一部分 以下是我绘制图表的方式: var chart_temperature = new Chart(ctx_temperature, { // The type of chart we want to create type: 'line', // The dat
var chart_temperature = new Chart(ctx_temperature, {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
labels: timeXValues,
fill: false, // no inner color
datasets: [{
label: 'Temperature',
borderColor: 'rgb(255, 99, 132)',
data: temperatureData
}]
},
// Configuration options go here
options: {
responsive: true,
layout: {
padding: {
bottom: 50
}
},
elements: {
point: {
radius: 0 // don't show points
},
line: {
fill: false
}
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'hour',
displayFormats: {
hour: 'DD/MM/YYYY HH:mm'
}
},
ticks: {
beginAtZero: false // tried true, and also removed all this as it used to be
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'T°C'
}
}]
},
showLines: true, // the points will be connected
// Optimization
animation: {
duration: 0 // general animation time
},
hover: {
animationDuration: 0 // duration of animations when hovering an item
},
responsiveAnimationDuration: 0 // animation duration after a resize
}
});
为什么chartjs使用0,而图表不是从0开始?我应该看哪里
感谢您的帮助:-
编辑:
注释scales.xAxes中的以下行将显示图表:
// type: 'time',
但是,由于时间戳被显示,X轴就变得毫无用处了。一个天才的想法终于爆发了!使用步长搜索相距太远的对象时,显示时间刻度最小值选项错误设置为0。 添加解决了这个问题 即使不推荐使用time min max选项,也应使用ticks.min和ticks.max:
ticks: {
min: startTimestamp,
max: endTimestamp
}
对我来说,我需要按分钟而不是秒来更新我的类型
xAxes: [ {
type: 'time',
time: {
unit: 'minute'
},
你应该接受你的答案,因为它帮助解决了我的问题@Junia Montana很高兴能帮到你。当我登录时,它显示为已接受。