我正在使用 Chartjs 在图表上绘制数据。它曾经有效,但我不知道为什么我不断得到uncaught exception: 0 and 1587533402000 are too far apart with stepSize of 1 hour,尽管 0 和 1587533402000 都不是我绘制的数据的一部分。
这是我绘制图表的方法:
\n\nvar chart_temperature = new Chart(ctx_temperature, {\n // The type of chart we want to create\n type: 'line',\n\n // The data for our dataset\n data: {\n labels: timeXValues,\n fill: false, // no inner color\n datasets: [{\n label: 'Temperature',\n borderColor: 'rgb(255, 99, 132)',\n data: temperatureData\n }]\n },\n\n // Configuration options go here\n options: {\n responsive: true,\n layout: {\n padding: {\n bottom: 50\n }\n },\n elements: {\n point: {\n radius: 0 // don't show points\n },\n line: {\n fill: false\n }\n },\n scales: {\n xAxes: [{\n type: 'time',\n time: {\n unit: 'hour',\n displayFormats: {\n hour: 'DD/MM/YYYY HH:mm'\n }\n },\n ticks: {\n beginAtZero: false // tried true, and also removed all this as it used to be\n }\n\n }],\n yAxes: [{\n scaleLabel: {\n display: true,\n labelString: 'T\xc2\xb0C'\n }\n }]\n\n },\n showLines: true, // the points will be connected\n // Optimization\n animation: {\n duration: 0 // general animation time\n },\n hover: {\n animationDuration: 0 // duration of animations when hovering an item\n },\n responsiveAnimationDuration: 0 // animation duration after a resize\n\n }\n});\nRun Code Online (Sandbox Code Playgroud)\n\n为什么 Chartjs 使用 0 而图表不是从 0 开始?我应该看哪里?
\n\n任何帮助表示赞赏:-)
\n\n编辑 :
\n\n注释以下行(在scales.xAxes)中可以显示图表:
// type: 'time',\nRun Code Online (Sandbox Code Playgroud)\n\n但由于显示时间戳,X 轴变得毫无用处。
\n一个天才的想法终于迸发出来了!are too far apart with stepSize 在 Chartjs git 存储库中搜索显示时间刻度 min 选项被错误地设置为 0。将这些 min max 添加到 xAxes 的时间选项解决了该问题。
即使 time min max 选项已被弃用,ticks.min但ticks.max应该使用:
ticks: {
min: startTimestamp,
max: endTimestamp
}
Run Code Online (Sandbox Code Playgroud)