我有一个奇怪的问题,我很困惑,但我相信在这里有人会知道我做错了什么.我的所有日期都显示不正确(即6月显示7月,7月显示8月)
我的代码在这里:
// Load the Visualization API and the piechart package.
google.load('visualization','1.0',{'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawVisualization);
// Callback that creates and populates a data table,// instantiates the pie chart,passes in the data and
// draws it.
function drawVisualization() {
var chartTable = new google.visualization.DataTable();
chartTable.addColumn('date','Date');
chartTable.addColumn('number','Sell');
chartTable.addColumn('number','GP');
chartTable.addRows(6);
chartTable.setValue(0,new Date( 2011,06,22 ));
chartTable.setValue(0,1,1316.90);
chartTable.setValue(0,2,456.05);
chartTable.setValue(1,21 ));
chartTable.setValue(1,1793.70);
chartTable.setValue(1,531.10);
chartTable.setValue(2,20 ));
chartTable.setValue(2,13559.25);
chartTable.setValue(2,1337.75);
chartTable.setValue(3,17 ));
chartTable.setValue(3,3034.15);
chartTable.setValue(3,892.30);
chartTable.setValue(4,16 ));
chartTable.setValue(4,568.45);
chartTable.setValue(4,175.05);
chartTable.setValue(5,15 ));
chartTable.setValue(5,7203.85);
chartTable.setValue(5,1343.45);
var date_formatter = new google.visualization.DateFormat({pattern: 'EEE,MMM-d'});
date_formatter.format(chartTable,0); // Apply format to first column of table
var currency_formatter = new google.visualization.NumberFormat({prefix: '$'});
currency_formatter.format(chartTable,1); // Apply format to second column of chart
currency_formatter.format(chartTable,2); // Apply format to third column of chart
// Create and draw the visualization.
chart = new google.visualization.LineChart(document.getElementById('chart'));
chart.draw(chartTable,{width: 900,height: 400,title: 'Sales Summary',vAxis: {maxValue: 20000,format: '$##,###',viewWindowMode: 'maximized'},hAxis: {direction: -1}
});
最佳答案
javascript Date对象从00开始计算月份,因此00 = 1月,01 = 2月等等…所以当你在月份字段中使用’06’构建日期时,它实际上是第7个月或7月
原文链接:https://www.f2er.com/js/429401.html