2
我有一個簡單的谷歌圖表:谷歌圖表自動分揀
google.setOnLoadCallback(drawVisualization);
function drawVisualization() {
var data = [
[new Date("Month"), "Shipments"],
[new Date("2015-05-01T04:00:00.000Z"), 51666],
[new Date("2014-11-01T04:00:00.000Z"), 53783],
[new Date("2015-02-01T05:00:00.000Z"), 63454],
[new Date("2014-12-01T05:00:00.000Z"), 63722],
[new Date("2015-03-01T05:00:00.000Z"), 63836],
[new Date("2015-09-01T04:00:00.000Z"), 63884],
[new Date("2015-04-01T04:00:00.000Z"), 68869],
[new Date("2015-08-01T04:00:00.000Z"), 68954],
[new Date("2015-01-01T05:00:00.000Z"), 72110],
[new Date("2015-06-01T04:00:00.000Z"), 77942],
[new Date("2015-07-01T04:00:00.000Z"), 86856],
[new Date("2014-10-01T04:00:00.000Z"), 92168]
];
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable(data);
var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div')
);
chart.draw(data);
}
<script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1.1','packages':['corechart']}]}"></script>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
您還可以在http://codepen.io/chug187/pen/GpQzNg看到這個動作。
它爲什麼會自動按數據中的日期排序?我希望圖表的列按出貨數量的升序顯示,但Google圖表按日期對數據進行排序。 DataTable,DataView或ComboChart類似乎沒有任何選項來確保數據顯示爲它存在於數據數組中。