ajax - live update google charts php+js -
i have candlestick chart drawn googlecarts api. can't live updating it.
next code html part of chart visualisation:
<script type='text/javascript'> function drawv(){ var = $.ajax({ url: "_ajax3.php", datatype:"html", async: false }).responsetext; console.log(a); var data = google.visualization.arraytodatatable([a],true); options = { chartarea:{ left: 55, top: 40, width: 760, height: 210 }, candlestick:{ fallingcolor:{ fill: "#41a6ef", stroke: "#41a6ef", strokewidth: 1 }, risingcolor:{ fill: "#f01717", stroke: "#f01717", strokewidth: 1 }, hollowisrising: true }, series: {0: {type: "candlesticks"}, 1: {type: "line", targetaxisindex:1, color:"#91d6ff"}}, legend:"none" }; chart = new google.visualization.combochart(document.getelementbyid("chart_div")); chart.draw(data, options); } google.setonloadcallback(drawv); setinterval(function(){ drawv(); }, 10000); </script> <div id='chart_div'></div>
i dont sure in ajax datatype, anyway, in worked case 'var data =...' line looks that:
var data = google.visualization.arraytodatatable([["18:26",20.79102,20.79102,20.79102,20.79102,20.79102],["18:27",20.79102,20.85,20.79102,20.85,20.82051],["18:28",20.85,20.8583,20.85,20.8583,20.85415], ["18:26",20.79102,20.79102,20.79102,20.79102,20.79102]],true);
and ajax return same data (without highlevel [ ]).
["18:26",20.79102,20.79102,20.79102,20.79102,20.79102],["18:27",20.79102,20.85,20.79102,20.85,20.82051],["18:28",20.85,20.8583,20.85,20.8583,20.85415], ["18:26",20.79102,20.79102,20.79102,20.79102,20.79102]
how can works? edit: next java error:uncaught error: not valid 2d array.
it looks ajax call returning string not valid json. modify server code add [
, ]
ends of string, use create datatable:
var data = google.visualization.arraytodatatable(json.parse(a),true);
Comments
Post a Comment