javascript - 当我使用特定的 dateTime 格式时,使用 CanvasJS 的图形为空
问题描述
我CanvasJS
用来在我的页面中显示图表。x
包含日期和y
数字..
我设置:
xValueType: "dateTime",
xValueFormatString: "YYYY-MM-DD HH:mm",
格式化我的日期,例如'2018-11-08 13:11'
但图表是空的.. dateFormat 出了点问题,但我不知道它是什么......
window.onload = function() {
var chart = new CanvasJS.Chart("grafima1", {
animationEnabled: true,
title: {
text: "title"
},
axisX: {
title: "date"
},
axisY: {
title: "Num",
suffix: "",
stripLines: [{
value: 3,
label: "3"
}]
},
data: [{
type: "line",
name: "Ώρες",
connectNullData: true,
xValueType: "dateTime",
xValueFormatString: "YYYY-MM-DD HH:mm",
yValueFormatString: "#,##0.##",
dataPoints: [{
x: '2018-11-08 13:11',
y: 2.0
},
{
x: '2018-11-05 15:23',
y: 5.0
}
]
}]
});
chart.render();
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<div id="grafima1" style="height: 370px; width: 100%;"></div>
解决方案
window.onload = function () {
var chart = new CanvasJS.Chart("grafima1", {
animationEnabled: true,
title: {
text: "title"
},
axisX: {
title: "date"
},
axisY: {
title: "Num",
suffix: "",
stripLines: [{
value: 3,
label: "3"
}]
},
data: [{
type: "line",
name: "Ώρες",
connectNullData: true,
xValueType: "dateTime",
xValueFormatString: "YYYY-MM-DD HH:mm",
yValueFormatString: "#,##0.##",
dataPoints: [{
x: new Date("2018-11-08 13:11"),
y: 2.0
},
{
x: new Date("2018-11-05 15:23"),
y: 5.0
}
]
}]
});
chart.render();
};
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="grafima1" style="height: 370px; width: 100%;"></div>
推荐阅读
- python - 使用 BeautifulSoup 从预订流程中获取结果
- reactjs - 你什么时候弹出一个 reactjs 应用程序
- operating-system - CPU 看到的指令序列与进程看到的指令序列有何不同?
- c# - 是否可以向 Active Directory 中的所有登录用户发送桌面通知?
- java - 此 URL 不支持 HTTP 方法 POST,在 Servlet 中有 doPost 方法
- java - 如何连接两个 IntStream?
- javascript - 如何同时使用php和js过滤内容
- ckeditor - CKEditor 找不到 getData 函数
- apache-flink - 是否有可能知道哪些元素被从窗口中逐出?
- java - 如何使用 Java 模型映射器将具有惰性属性的实体转换为 DTO