gpt4 book ai didi

javascript - 谷歌图表日期格式无法显示

转载 作者:行者123 更新时间:2023-12-02 23:52:37 24 4
gpt4 key购买 nike

我正在使用 Google Chart 来显示我的销售图表

在我的图表中需要显示按日期销售

X 轴为日期,Y 轴为金额

但是在谷歌图表中,我无法打印日期。下面是我的代码

<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(){
var data = new google.visualization.DataTable();
data.addColumn('datetime', 'Time of Day');
data.addColumn('number','Head Office');
data.addColumn('number','Mohans Shoppy');
data.addColumn('number','My shoppy');
data.addRows([
[[new Date(2019,03,02)],2599,0,0],[[new Date(2019,03,03)],0,0,0],[[new Date(2019,03,04)],28625,0,15900],[[new Date(2019,03,05)],3934,0,0],[[new Date(2019,03,06)],0,0,0],[[new Date(2019,03,07)],3201,0,0],[[new Date(2019,03,09)],1500,0,0],
]);
var options = {
title: 'Sales Chart',
legend: { position: 'bottom' },
width: 900,
height: 500

};

var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</body>
</html>

我在控制台中收到错误:未捕获( promise 中)错误:类型不匹配。值 Tue Apr 02 2019 00:00:00 GMT+0530(印度标准时间)与列索引 0 中的类型日期时间不匹配

最佳答案

[new Date(2019,03,02),2599,0,0],
[new Date(2019,03,03),0,0,0],
[new Date(2019,03,04),28625,0,15900],
[new Date(2019,03,05),3934,0,0],
[new Date(2019,03,06),0,0,0],
[new Date(2019,03,07),3201,0,0],
[new Date(2019,03,09),1500,0,0],

您添加了一个额外的 [ ]。

关于javascript - 谷歌图表日期格式无法显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55574083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com