javascript – Google Charts API:显示的日期不正确

前端之家收集整理的这篇文章主要介绍了javascript – Google Charts API:显示的日期不正确前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个奇怪的问题,我很困惑,但我相信在这里有人会知道我做错了什么.我的所有日​​期都显示不正确(即6月显示7月,7月显示8月)

我的代码在这里:

  1. // Load the Visualization API and the piechart package.
  2. google.load('visualization','1.0',{'packages':['corechart']});
  3. // Set a callback to run when the Google Visualization API is loaded.
  4. google.setOnLoadCallback(drawVisualization);
  5. // Callback that creates and populates a data table,// instantiates the pie chart,passes in the data and
  6. // draws it.
  7. function drawVisualization() {
  8. var chartTable = new google.visualization.DataTable();
  9. chartTable.addColumn('date','Date');
  10. chartTable.addColumn('number','Sell');
  11. chartTable.addColumn('number','GP');
  12. chartTable.addRows(6);
  13. chartTable.setValue(0,new Date( 2011,06,22 ));
  14. chartTable.setValue(0,1,1316.90);
  15. chartTable.setValue(0,2,456.05);
  16. chartTable.setValue(1,21 ));
  17. chartTable.setValue(1,1793.70);
  18. chartTable.setValue(1,531.10);
  19. chartTable.setValue(2,20 ));
  20. chartTable.setValue(2,13559.25);
  21. chartTable.setValue(2,1337.75);
  22. chartTable.setValue(3,17 ));
  23. chartTable.setValue(3,3034.15);
  24. chartTable.setValue(3,892.30);
  25. chartTable.setValue(4,16 ));
  26. chartTable.setValue(4,568.45);
  27. chartTable.setValue(4,175.05);
  28. chartTable.setValue(5,15 ));
  29. chartTable.setValue(5,7203.85);
  30. chartTable.setValue(5,1343.45);
  31. var date_formatter = new google.visualization.DateFormat({pattern: 'EEE,MMM-d'});
  32. date_formatter.format(chartTable,0); // Apply format to first column of table
  33. var currency_formatter = new google.visualization.NumberFormat({prefix: '$'});
  34. currency_formatter.format(chartTable,1); // Apply format to second column of chart
  35. currency_formatter.format(chartTable,2); // Apply format to third column of chart
  36. // Create and draw the visualization.
  37. chart = new google.visualization.LineChart(document.getElementById('chart'));
  38. chart.draw(chartTable,{width: 900,height: 400,title: 'Sales Summary',vAxis: {maxValue: 20000,format: '$##,###',viewWindowMode: 'maximized'},hAxis: {direction: -1}
  39. });

正确显示所有数据除了日期 – 而不是显示在图表6月它显示7月???这个月的同一天,但月份是错的?

最佳答案
javascript Date对象从00开始计算月份,因此00 = 1月,01 = 2月等等…所以当你在月份字段中使用’06’构建日期时,它实际上是第7个月或7月

猜你在找的JavaScript相关文章