gpt4 book ai didi

php - 谷歌图表 : Object 2013-07-25 has no method 'getTime

转载 作者:行者123 更新时间:2023-11-30 01:26:59 25 4
gpt4 key购买 nike

我正在尝试使用谷歌图表 API 绘制图表。一列包含日期,另一列包含数字。

这是获取我的数据的 php 页面:

<?php
include 'core/init.php';

$result = mysql_query('SELECT amountDone, resultDate FROM result');

$table = array();
$table['cols'] = array(
array('label' => 'Done', 'type' => 'number'),
array('label' => 'Date', 'type' => 'date')
);

$rows = array();
while($r = mysql_fetch_assoc($result)) {
$temp = array();
$temp[] = array('v' => (int)$r['amountDone']);
$temp[] = array('v' => $r['resultDate']);
$rows[] = array('c' => $temp);
}

$table['rows'] = $rows;

$jsonTable = json_encode($table);

echo $jsonTable;

?>

返回的json数据如下:

{"cols":[{"label":"Done","type":"int"},{"label":"Date","type":"date"}],"rows":[{"c":    [{"v":1200},{"v":"2013-07-25"}]},{"c":[{"v":3600},{"v":"2013-07-26"}]}]}

在我的主页中,我尝试使用以下代码绘制图表:

<script type="text/javascript">

// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

function drawChart() {
var jsonData = $.ajax({
url: "get_json.php",
dataType:"json",
async: false
}).responseText;

// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}

</script>

但我总是收到以下错误(取决于我使用的浏览器,但它们包含我猜的相同信息,这个是 chrome):

Object 2013-07-25 has no method 'getTime

任何人都知道这可能意味着什么,因为我没有收到任何其他错误

提前致谢!

最佳答案

将我的查询更改为:

$result = mysql_query("SELECT DATE_FORMAT(resultDate, '%W, %D %M %Y') as Datum,    SUM(amountDone) as AmountD, SUM(amountToDo) as AmountT
FROM result
GROUP BY resultDate");

并且类型现在是字符串。奇迹般有效。 :)

关于php - 谷歌图表 : Object 2013-07-25 has no method 'getTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17890345/

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