谷歌时间线图无效,我将python datatime转换为谷歌日期字符串,然后我将我的数组传递给谷歌图表,谷歌图表未显示并显示"无效的数据表格式:必须有3或4个数据列"在html页面。
Json对象:`
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
google.charts.load("current", {packages:["timeline"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('example3.1');
var chart = new google.visualization.Timeline(container);
// var dataTable = google.visualization.arrayToDataTable(
/*
[
['Category', 'Name', {role: 'style'}, {type: 'date'}, {type: 'date'}],
//'Date(2000, 8, 5)'
['BINGEN', '1', '#FF0000', 'Date(2014, 7, 1,12,01,01)', 'Date(2014, 7, 1,14,03,02)'],
['NRT', '1', '#228B22', 'Date(2014, 7, 1,10,10,10)', 'Date(2014, 7, 1,12,10,10)'],
['REGRESSION', '1', '#FF0000', 'Date(2014, 7, 1,09,10,12)', 'Date(2014, 7, 1,12,02,01)'],
['BINGEN', '2', '#FF0000', 'Date(2014, 7, 1,14,30,01)', 'Date(2014, 7, 1,16,03,02)'],
['NRT', '2', '#228B22', 'Date(2014, 7, 1,14,10,10)', 'Date(2014, 7, 1,16,10,10)'],
['REGRESSION', '2', '#FFFF00', 'Date(2014, 7, 1,14,10,12)', 'Date(2014, 7, 1,20,02,01)']
]);
*/
var jsonData = $.ajax({
url: "/jenkins/2017-02-10",
dataType: "json",
async: false
}).responseText;
var my_data = JSON.parse(jsonData);
my_data.splice(0, 0, ['Category', 'Name', {role: 'style'}, {type: 'date'}, {type: 'date'}]);
var dataTable = new google.visualization.DataTable(my_data);
chart.draw(dataTable);
}
</script>
<div id="example3.1" style="height: 200px;"></div>
</body>
</html>
&#13;
`
以下是html页面
答案 0 :(得分:2)
如果您使用的是简单的数组数据,请在问题中注明
你不能直接将其反馈给 - &gt; google.visualization.DataTable
需要使用静态方法 - &gt; google.visualization.arrayToDataTable
var dataTable = google.visualization.arrayToDataTable(my_data);
直接提供给 - &gt; google.visualization.DataTable
,
必须采用此处找到的json格式...
Format of the Constructor's JavaScript Literal data Parameter