0
我使用谷歌圖表折線圖作爲價格圖表。每天有一個值或缺少一些日子。Google圖表時間軸不是按時間順序排列的
該圖不是函數,而是曲線。我的意思是圖上有一個捲曲,它回溯到時間。 1月底和2月的乞討之間出現了問題。
圖爲here或在這裏:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1.0', { 'packages': ['corechart'] });
google.setOnLoadCallback(drawChart);
function drawChart() {
drawChartInner('chart_div0', '/analyza/data?obec_id=554782&from=11%2F17%2F2013%2017%3A54%3A09&to=02%2F15%2F2014%2017%3A54%3A09&kat=1', 'Vývoj cen bytů Prodej Praha');
drawChartInner('chart_div1', '/analyza/data?obec_id=554782&from=11%2F17%2F2013%2017%3A54%3A09&to=02%2F15%2F2014%2017%3A54%3A09&kat=8', 'Vývoj cen bytů Pronájem Praha');
}
function drawChartInner(chartElement, surl, jvtitle) {
var jsonData = $.ajax({
url: surl,
dataType: "json",
async: false,
}).responseText;
var dataTable = new google.visualization.DataTable(jsonData);
var dataView = new google.visualization.DataView(dataTable);
var chart = new google.visualization.LineChart(document.getElementById(chartElement));
var options = {
legend: 'none',
pointSize: 3,
title: jvtitle,
vAxis: { title: 'Kč/m2' },
hAxis: { format: 'dd.MM. yyyy' },
};
chart.draw(dataView, options);
}
</script>
和底層數據源here或在這裏:
{ "cols": [
{"id":"Datum","label":"Datum","type":"date"},
{"id":"Cena","label":"Cena","type":"number"}],"rows": [
{"c":[{"v":"Date(2013,11,18)","f":"11/18/2013"},{"v":47522.172,"f":"47522Kč/m2"}]},
{"c":[{"v":"Date(2013,11,19)","f":"11/19/2013"},{"v":47522.172,"f":"47522Kč/m2"}]},
{"c":[{"v":"Date(2013,11,20)","f":"11/20/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2013,11,21)","f":"11/21/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2013,11,22)","f":"11/22/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2013,11,23)","f":"11/23/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2013,11,24)","f":"11/24/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2013,11,25)","f":"11/25/2013"},{"v":47862.149,"f":"47862Kč/m2"}]},
{"c":[{"v":"Date(2014,01,24)","f":"1/24/2014"},{"v":48190.538,"f":"48191Kč/m2"}]},
{"c":[{"v":"Date(2014,01,25)","f":"1/25/2014"},{"v":48190.538,"f":"48191Kč/m2"}]},
{"c":[{"v":"Date(2014,01,27)","f":"1/27/2014"},{"v":48101.545,"f":"48102Kč/m2"}]},
{"c":[{"v":"Date(2014,01,28)","f":"1/28/2014"},{"v":48168.921,"f":"48169Kč/m2"}]},
{"c":[{"v":"Date(2014,01,29)","f":"1/29/2014"},{"v":47738.429,"f":"47738Kč/m2"}]},
{"c":[{"v":"Date(2014,01,30)","f":"1/30/2014"},{"v":47892.864,"f":"47893Kč/m2"}]},
{"c":[{"v":"Date(2014,01,31)","f":"1/31/2014"},{"v":48105.021,"f":"48105Kč/m2"}]},
{"c":[{"v":"Date(2014,02,01)","f":"2/1/2014"},{"v":48017.033,"f":"48017Kč/m2"}]},
{"c":[{"v":"Date(2014,02,02)","f":"2/2/2014"},{"v":48233.741,"f":"48234Kč/m2"}]},
{"c":[{"v":"Date(2014,02,03)","f":"2/3/2014"},{"v":48956.097,"f":"48956Kč/m2"}]},
{"c":[{"v":"Date(2014,02,04)","f":"2/4/2014"},{"v":48865.456,"f":"48865Kč/m2"}]},
{"c":[{"v":"Date(2014,02,05)","f":"2/5/2014"},{"v":49222.782,"f":"49223Kč/m2"}]},
{"c":[{"v":"Date(2014,02,06)","f":"2/6/2014"},{"v":48510.947,"f":"48511Kč/m2"}]},
{"c":[{"v":"Date(2014,02,08)","f":"2/8/2014"},{"v":49209.499,"f":"49209Kč/m2"}]},
{"c":[{"v":"Date(2014,02,09)","f":"2/9/2014"},{"v":49135.071,"f":"49135Kč/m2"}]},
{"c":[{"v":"Date(2014,02,10)","f":"2/10/2014"},{"v":49430.235,"f":"49430Kč/m2"}]}]}
我相信我使用了正確的日期時間格式日期(2014,01,31)
我不明白我在做什麼錯。
我相信格式應該是'new Date()':https://developers.google.com/chart/interactive/docs/gallery/annotatedtimeline –
新的Date()不適用於json格式。我finnaly找到答案,見下圖。 – qub1n