【发布时间】:2021-02-17 01:42:36
【问题描述】:
我似乎无法让 Chart.js 处理日期。我尝试了很多不同的方法:
let examChart = document.getElementById("examChart").getContext("2d");
let examLineChart = new Chart(examChart, {
type: "line",
data: [
{ t: new Date("2015-3-15 13:3"), y: 12 },
{ t: new Date("2015-3-25 13:2"), y: 21 },
{ t: new Date("2015-4-25 14:12"), y: 32 }
],
options: {
label: "placeholder"
}
});
还有:
let examChart = document.getElementById("examChart").getContext("2d");
let examLineChart = new Chart(examChart, {
type: "line",
data: [
{ t: "2015-3-15 13:3", y: 12 },
{ t: "2015-3-25 13:2", y: 21 },
{ t: "2015-4-25 14:12", y: 32 }
],
options: {
label: "placeholder"
}
});
还有:
let examChart = document.getElementById("examChart").getContext("2d");
let examLineChart = new Chart(examChart, {
type: "line",
data: [
{ t: "Sun Mar 15 2015 12:03:45 GMT+0000 (GMT Standard Time)", y: 12 },
{ t: "Wed Mar 25 2015 12:02:15 GMT+0000 (GMT Standard Time)", y: 21 },
{ t: "Sat Apr 25 2015 13:12:30 GMT+0100 (GMT Daylight Time)", y: 32 }
],
options: {
label: "placeholder"
}
});
为了涵盖我的一些尝试,即使在阅读文档 (http://www.chartjs.org/docs/latest/axes/cartesian/time.html) 之后,我似乎也无法正确设置日期(他们实际上并没有给出示例)
正在使用的 HTML:
<div class="container">
<canvas id="examChart"></canvas>
</div>
我只是不知道,虽然我认为这是一个相当简单的问题,任何帮助将不胜感激。
【问题讨论】:
标签: javascript date chart.js ejs