gpt4 book ai didi

google-visualization - Google 日期时间格式化程序不适用于 Google 折线图

转载 作者:行者123 更新时间:2023-12-04 04:35:34 31 4
gpt4 key购买 nike

出于某种原因,无论我做什么以及我如何尝试,这个日期格式化程序都不起作用。工具提示仍然显示错误的格式。你可以试试代码here .

在代码中我必须注释掉 formatter.format(dataTable, 0)否则它不起作用。

有没有办法让工具提示显示正确的格式?

function drawVisualization() {
// Create and populate the data table.
var dataTable= new google.visualization.DataTable();
dataTable.addColumn('datetime', 'Year');
dataTable.addColumn('number', 'Apple');
dataTable.addColumn('number', 'Android');
dataTable.addRows([
[new Date("6/22/2009 16:00:00"),425,45 ],
[new Date("6/8/2009 16:00:00"),424, 43],
[new Date("5/26/2009 16:00:00"),417, 434],
[new Date("5/11/2009 16:00:00"),390, 343],
[new Date("4/27/2009 16:00:00"),393, 45],
[new Date("4/13/2009 16:00:00"),392, 45],
[new Date("3/30/2009 16:00:00"),369, 868],
[new Date("3/16/2009 16:00:00"),330, 68],
[new Date("3/2/2009 16:00:00"),308, 86],
[new Date("2/17/2009 16:00:00"),346, 43],
[new Date("2/2/2009 16:00:00"),371, 38],
[new Date("1/20/2009 16:00:00"),324, 86],
[new Date("1/5/2009 16:00:00"),315, 78],
[new Date("12/22/2008 16:00:00"),300, 536],
[new Date("12/8/2008 16:00:00"),315, 38],
[new Date("11/24/2008 16:00:00"),292, 78],
[new Date("11/10/2008 16:00:00"),310, 99],
[new Date("10/27/2008 16:00:00"),359, 78],
[new Date("10/13/2008 16:00:00"),372, 68],
[new Date("9/29/2008 16:00:00"),386, 68],
[new Date("9/15/2008 16:00:00"),449, 78],
[new Date("9/2/2008 16:00:00"),444, 69],
[new Date("8/25/2008 16:00:00"),463, 25],
[new Date("8/11/2008 16:00:00"),510, 53],
[new Date("7/28/2008 16:00:00"),467, 38],
[new Date("7/14/2008 16:00:00"),481, 45],
[new Date("6/30/2008 16:00:00"),537, 85],
[new Date("6/16/2008 16:00:00"),546, 123],
[new Date("6/2/2008 16:00:00"),567, 234],
[new Date("5/19/2008 16:00:00"),544, 45],
[new Date("5/5/2008 16:00:00"),573, 54],
[new Date("4/21/2008 16:00:00"),544, 88],
[new Date("4/7/2008 16:00:00"),457, 86],
[new Date("3/24/2008 16:00:00"),438, 78],
[new Date("3/10/2008 16:00:00"),437, 68],
[new Date("2/25/2008 16:00:00"),471, 35],
[new Date("2/11/2008 16:00:00"),529, 45],
[new Date("1/28/2008 16:00:00"),515, 47],
[new Date("1/14/2008 16:00:00"),600, 57],
[new Date("12/31/2007 16:00:00"),657, 57],
[new Date("12/17/2007 16:00:00"),696, 83],
[new Date("12/3/2007 16:00:00"),714, 387],
[new Date("11/19/2007 16:00:00"),676, 75],
[new Date("11/5/2007 16:00:00"),663, 85],
[new Date("10/22/2007 16:00:00"),674, 733],
[new Date("10/8/2007 16:00:00"),637, 327],
[new Date("9/24/2007 16:00:00"),567, 345],
[new Date("9/10/2007 16:00:00"),528, 45],
[new Date("8/27/2007 16:00:00"),515, 324]]);

// For some reason, it doesn't work correctly
var formatter = google.visualization.DateFormat({pattern: 'yyyy/MM/dd'});
//formatter.format(dataTable, 0);

// Create and draw the visualization.
var chart = new google.visualization.LineChart(document.getElementById('visualization'));
chart.draw(dataTable, {curveType: "function"});
}

最佳答案

您的格式代码中有语法错误。

错误:

var formatter = google.visualization.DateFormat({pattern: 'yyyy/MM/dd'});

对:
var formatter = new google.visualization.DateFormat({pattern: 'yyyy/MM/dd'});

您需要在 DateFormat 参数之前添加"new"。这一单一更改使您的代码正常工作。

关于google-visualization - Google 日期时间格式化程序不适用于 Google 折线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19802474/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com