Reputation: 25138
I use google chart line graph as a price graph. There is one value for each day or some days are missing.
The graph is not a function, but a curve. I mean there is a crimp on the graph, it goes back in time. There is something wrong between the end of January and the begging of February.
The graph is here or 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>
and underlying datasource here or 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"}]}]}
I believe I use the correct datetime format Date(2014,01,31)
I don't understand what I am doing wrong.
Upvotes: 0
Views: 159
Reputation: 25138
Finally I have found a problem. As a doc says, the month are zero based. This means that the 28th of February 2014 is not "Date(2014,2,28)", but "Date(2014,1,28)".
Now it works.
Upvotes: 2