Google Charts表显示错误的日期

时间:2016-07-12 15:30:49

标签: google-visualization

In this example谷歌排行榜的日期为1/1/16,并显示12/31/15。我需要使用某种时区吗?

<div id="chart"></div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:['corechart', 'table']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
  var data = new google.visualization.DataTable();
  data.addColumn('date', 'dt'); 
  data.addRows([[new Date("2016-01-01")]]);
  var view = new google.visualization.DataView(data);
  var table = new google.visualization.Table(document.getElementById('chart'));
  table.draw(data);
}
</script>

enter image description here

1 个答案:

答案 0 :(得分:0)

与谷歌可视化无关,真正的答案就在这里......
Why does Date.parse give incorrect results?

使用'01/01/2016'之类的格式来获得预期的结果......