我用 Googlechart 制作了一个图表。但它仅在 Safari 中不起作用。 我收到错误:
a.getTime is not a function. (in 'a.getTime()','a.getTime' is undefined).
我的日期代码:
var date = new Date();
这是我的行代码:
data.addRows([
<?php
$now = date();
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -7 Day")).'), 80, 8, 96, , 100, , , , , 38, , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -6 Day")).'), , 12, , , 102, , , , , , , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -5 Day")).'), 100, , , , , , , , , 36 , , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -4 Day")).'), , , , , , , , , , 36, , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -3 Day")).'), , 18, 93, , , , , , , , , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -2 Day")).'), 120, , , , , , , , , , , ,],';
echo '[new Date('.date("Y, m, d, H, i, s", strtotime("$now -1 month -1 Day")).'), 85, 14, 98, , 54, , , , , , , ,],';
$query = "SELECT * FROM `test` ORDER BY date ASC";
if ($result = $mysqli->query($query)) {
while ($arr = $result->fetch_assoc()) {
$date = $arr['date'];
echo '
[
new Date('.date("Y, m, d, H, i, s", strtotime("$date -1 month")).'),
'.$arr['test1'].',
'.$arr['test2'].',
'.$arr['test3'].',
'.$arr['test4'].',
'.$arr['test5'].',
'.$arr['test7'].',
'.$arr['test8'].',
'.$arr['test9'].',
'.$arr['test10'].',
'.$arr['test11'].',
'.$arr['test12'].',
'.$arr['test13'].',
],
';
}
}
?>
]
);
我认为日期出了问题。
我不明白为什么它不能仅在 Safari 中运行。
最佳答案
您可以尝试使用 json 字符串格式加载日期
“日期(2017, 1, 13, 0, 0, 0)”
这可能需要对代码布局进行一些重大更改,
但如果它能起作用的话可能是值得的
不要使用 addRows
方法,而是先构建 json 字符串,
然后创建DataTable
请参阅以下工作片段...
google.charts.load('current', {
callback: function () {
var jsonData = '{"cols": [{"label": "Date", "type": "date"}, {"label": "Value", "type": "number"}], "rows": [{"c":[{"v": "Date(2017, 1, 13, 0, 0, 0)"}, {"v": 1}]}, {"c":[{"v": "Date(2017, 1, 14, 0, 0, 0)"}, {"v": 2}]}]}';
var data = new google.visualization.DataTable(jsonData);
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
containerId: 'chart_div',
dataTable: data
});
table.draw();
},
packages: ['table']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
关于javascript - Googlechart 仅在 Safari 中无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42222442/