【问题标题】:Google chart Date format unable to Display谷歌图表日期格式无法显示
【发布时间】:2019-04-08 12:59:36
【问题描述】:

我正在使用 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>

我在控制台中收到错误:未捕获(承诺中)错误:类型不匹配。值 2019 年 4 月 2 日星期二 00:00:00 GMT+0530(印度标准时间)与列索引 0 中的类型日期时间不匹配

【问题讨论】:

    标签: javascript html charts google-visualization


    【解决方案1】:
    [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],  
    

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

    【讨论】:

    • 非常感谢...它有效
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多