谷歌图表API:显示不正确的日期
Google Charts API: Incorrect date being displayed
我有一个奇怪的问题,我感到困惑,但我相信有人在这里会知道我做错了什么。我所有的日期都显示不正确(即六月显示七月,七月显示八月)
我的代码:
// 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, 0, new Date( 2011, 06, 22 ));
chartTable.setValue(0, 1, 1316.90);
chartTable.setValue(0, 2, 456.05);
chartTable.setValue(1, 0, new Date( 2011, 06, 21 ));
chartTable.setValue(1, 1, 1793.70);
chartTable.setValue(1, 2, 531.10);
chartTable.setValue(2, 0, new Date( 2011, 06, 20 ));
chartTable.setValue(2, 1, 13559.25);
chartTable.setValue(2, 2, 1337.75);
chartTable.setValue(3, 0, new Date( 2011, 06, 17 ));
chartTable.setValue(3, 1, 3034.15);
chartTable.setValue(3, 2, 892.30);
chartTable.setValue(4, 0, new Date( 2011, 06, 16 ));
chartTable.setValue(4, 1, 568.45);
chartTable.setValue(4, 2, 175.05);
chartTable.setValue(5, 0, new Date( 2011, 06, 15 ));
chartTable.setValue(5, 1, 7203.85);
chartTable.setValue(5, 2, 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}
});
是显示所有数据正确除了日期-而不是在图表上显示6月它显示7月??同一个月的同一天,但月份错了?
javascript Date对象从00开始计算月份,所以00 = 1月,01 = 2月,等等…所以当你在月份字段中使用'06'构建日期时,它实际上是第七个月,或7月
为了构建wolv2012响应,我刚刚遇到了这个问题:JS的月计数系统是基于零的,而MySQL返回的月数在1到12之间。
我的日期在Javascript new Date(...)
之前被格式化在SQL中,我通过在我的月号上附加一个"-1"来弥补这一点,而仍然在SQL中:
SELECT DATE_FORMAT(jobs.date, '%Y, %m-1, %d') ...
我有同样的问题,这个线程帮助了我,谢谢!我知道这篇文章很老了,但它与我有关,所以如果它将来对别人有帮助的话:
我对SQL Server的修复是:SELECT cast(DATEADD(month,-1,[mydate]) as newdate
实际上,对于我使用的谷歌注释图的格式,我必须这样格式化:replace(cast(DATEADD(month,-1,[mydate]) as date),'-', ',') as dateforJSON
相关文章:
- 从int值来看,Javascript日期不正确
- Safari浏览器中的格式化日期不正确
- 格式为nnnnnnnn的字符串在电子表格中显示为日期或不正确
- JavaScript:日期不正确
- x轴上的日期不正确
- asp.net 图表控件显示不正确的工具提示日期时间值
- 日期() 结果不正确
- Javascript Date 对象不正确的日期
- 时间戳中的日期不正确,例如DD_MM_YYYY_HH_MI_SS
- Flot工具提示中显示的日期不正确
- Angular UI网格日期格式不正确
- MongoDB日期时间值存储不正确
- 日期在Highcharts图中显示不正确,时间数据不规则
- Jquery日期选择器图标位置不正确
- 输入日期字段中显示的星期几不正确
- D3嵌套格式设置日期不正确
- 在x轴使用毫秒时接收到不正确的日期时间
- JS日期对象解析不正确
- Javascript日期格式显示不正确的时间
- ECMAScript 5.1规范不正确?日期构造函数日期/时间格式解析为UTC