gpt4 book ai didi

php - 为什么错误 "c.getTimezoneOffset is not a function"?

转载 作者:可可西里 更新时间:2023-11-01 07:43:52 26 4
gpt4 key购买 nike

我尝试使用从 mysql 检索数据的 Google 图表制作简单的折线图。我的 json 工作但是当我尝试以完整编码调用它时,它说“c.getTimezoneOffset 不是函数”。

这里是我的 json php

<?php
include("config.php");

$query = "SELECT * FROM reading";
$sql = mysqli_query($con, $query);

if (!$sql) {
die("Error running $sql: " . mysql_error());
}

$results = array(
'cols' => array (
array('label' => 'Date', 'type' => 'datetime'),
array('label' => 'API', 'type' => 'number')
),
'rows' => array()
);
while($row = mysqli_fetch_assoc($sql)) {

$year=date("Y", strtotime($row['time']));
$month=date("m", strtotime($row['time']));
$day=date("d", strtotime($row['time']));
$hour=date("H", strtotime($row['time']));
$minute=date("i", strtotime($row['time']));
$second=date("s", strtotime($row['time']));

$results['rows'][] = array('c' => array(
array('v' => "time($year, $month, $day, $hour, $minute, $second)"),
array('v' => $row['api'])
));
}
$json = json_encode($results, JSON_NUMERIC_CHECK);
echo $json;
?>

这是我的json

{"cols":[{"label":"Date","type":"datetime"},
"label":"API","type":"number"}],
"rows":[{"c":[{"v":"time(2016, 05, 22, 12, 24, 26)"},{"v":26}]},
{"c":[{"v":"time(2016, 05, 22, 12, 24, 41)"},{"v":26}]},
{"c":[{"v":"time(2016, 05, 22, 12, 24, 56)"},{"v":27}]}]}

这是我的html代码

<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<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() {
$.ajax({
url: 'getData.php',
dataType: 'json',
success: function (jsonData) {
// 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.LineChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
});
}

</script>
</head>

<body>
<div id="chart_div"></div>
</body>
</html>

最佳答案

我遇到了同样的错误,不得不修改我的 JSON 以生成如下所示的字符串:

"c":[{"v":"日期(2018,9,16)","f":null}

这意味着我的代码必须解析出年、月和日才能将它们拼凑起来。我正在使用 JSP,但希望这可以帮助那里的人:

createDateObj.put("v", "Date("+ createYear + "," + createMonth + "," + createDay + ")");

而不是像这样简单地使用从 mySQL 返回的日期:

createDateObj.put("v", createDate);

关于php - 为什么错误 "c.getTimezoneOffset is not a function"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37372314/

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