【问题标题】:Google Chart Calendar does not work november and december谷歌图表日历在 11 月和 12 月不起作用
【发布时间】:2016-02-05 18:55:17
【问题描述】:

当我将 Google Chart API 与 Calendar 包一起使用时,当日期为 11 月或 12 月时,它不会绘制数据。

我正在使用https://developers.google.com/chart/interactive/docs/gallery/calendar 上提供的 Google 代码示例。

而且,即使使用 google 示例,如果我将月份更改为 11 月或 12 月(索引 10 或 11),则不会绘制数据,但其他月份都可以。

来自谷歌的示例代码:

    <html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["calendar"]});
      google.setOnLoadCallback(drawChart);

   function drawChart() {
       var dataTable = new google.visualization.DataTable();
       dataTable.addColumn({ type: 'date', id: 'Date' });
       dataTable.addColumn({ type: 'number', id: 'Won/Loss' });
       dataTable.addRows([
          [ new Date(2012, 3, 13), 37032 ],
          [ new Date(2012, 3, 14), 38024 ],
          [ new Date(2012, 3, 15), 38024 ],
          [ new Date(2012, 3, 16), 38108 ],
          [ new Date(2012, 3, 17), 38229 ],
          // Many rows omitted for brevity.
          [ new Date(2013, 9, 4), 38177 ],
          [ new Date(2013, 9, 5), 38705 ],
          [ new Date(2013, 9, 12), 38210 ],
          [ new Date(2013, 9, 13), 38029 ],
          [ new Date(2013, 9, 19), 38823 ],
          [ new Date(2013, 9, 23), 38345 ],
          [ new Date(2013, 9, 24), 38436 ],
          [ new Date(2013, 9, 30), 38447 ]
        ]);

       var chart = new google.visualization.Calendar(document.getElementById('calendar_basic'));

       var options = {
         title: "Red Sox Attendance",
         height: 350,
       };

       chart.draw(dataTable, options);
   }
    </script>
  </head>
  <body>
    <div id="calendar_basic" style="width: 1000px; height: 350px;"></div>
  </body>
</html>

【问题讨论】:

  • 这仍然是 2015 年的错误。

标签: charts calendar


【解决方案1】:

您确定问题不是由于大小而没有显示月份吗? 以上面的示例代码并将月份更改为 10(11 月)和 11(12 月),它可以正常工作。

查看此jsfiddle 了解结果。您可能会注意到您必须滚动才能查看最近几个月。我怀疑你的 css 有一些限制,会影响后面的几个月。

jsfiddle 中的代码:

<html>
  <head>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1.1", {packages:["calendar"]});
      google.setOnLoadCallback(drawChart);

   function drawChart() {
       var dataTable = new google.visualization.DataTable();
       dataTable.addColumn({ type: 'date', id: 'Date' });
       dataTable.addColumn({ type: 'number', id: 'Won/Loss' });
       dataTable.addRows([
          [ new Date(2012, 10, 13), 37032 ],
          [ new Date(2012, 10, 14), 38024 ],
          [ new Date(2012, 10, 15), 38024 ],
          [ new Date(2012, 11, 16), 38108 ],
          [ new Date(2012, 11, 17), 38229 ],
          // Many rows omitted for brevity.
          [ new Date(2013, 10, 4), 38177 ],
          [ new Date(2013, 10, 5), 38705 ],
          [ new Date(2013, 10, 12), 38210 ],
          [ new Date(2013, 10, 13), 38029 ],
          [ new Date(2013, 11, 19), 38823 ],
          [ new Date(2013, 11, 23), 38345 ],
          [ new Date(2013, 11, 24), 38436 ],
          [ new Date(2013, 11, 30), 38447 ]
        ]);

       var chart = new google.visualization.Calendar(document.getElementById('calendar_basic'));

       var options = {
         title: "Red Sox Attendance",
         height: 350,
       };

       chart.draw(dataTable, options);
   }
    </script>
  </head>
  <body>
    <div id="calendar_basic" style="width: 1000px; height: 350px;"></div>
  </body>
</html>

【讨论】:

  • 该示例并未显示它无法正常工作。我同意那个。 11 月和 12 月不适用于 Google 日历。
  • 这是否意味着您在示例 jsfiddle 中看不到它们?请详细说明,我看到日期标记为 11 月和 12 月。
  • 是的。我联系了 Google Vis 的 Daniel,他知道这个问题。它与时区有关。我在 GMT -3 的巴西。他告诉我很快就会修复。
  • 我明白了!这可以解释为什么它对我有用(我在不同的时区)。谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-02
  • 1970-01-01
  • 2014-12-30
  • 1970-01-01
相关资源
最近更新 更多