php - Get json data into Highcharts scatter plot -
i cannot highcharts graph scatter plot of 2 series. actually, graph isn't showing up. please me determine i'm doing wrong. cannot find scatter plot example go off of , new this. i've got json data php file looks like:
[[65,44],[66,37],[67,42],[68,55],[65,50],[65,41],[65,41],[68,41],[69,42],[70,47],[69,55],[67,45],[67,49],[67,53],[67,49],[68,51],[68,55],[68,57],[70,53],[69,66],[68,54],[69,52],[68,48]][[75,36],[72,42],[75,44],[69,56],[72,40],[73,37],[77,34],[77,40],[74,50],[77,45],[77,43],[75,47],[73,52],[73,50],[75,44],[72,54],[71,57],[72,57],[74,55],[74,54],[75,47],[78,45],[75,43]]
this should 2 series in (x,y) format. want graph these on scatter plot in highcharts. highcharts code is:
<script type="text/javascript"> $(function () { var chart; $(document).ready(function() { $.getjson("comfortgb1b.php", function(json) { chart = new highcharts.chart({ chart: { renderto: 'container4', type: 'scatter', marginright: 175, marginbottom: 50 }, title: { text: 'comfort level', x: -20 //center }, subtitle: { text: '', x: -20 }, xaxis: { title: { enabled: true, text: 'temp (f)' }, min: 60, max: 85, startontick: true, endontick: true, showlastlabel: true }, yaxis: { title: { text: 'humidity (%rh)' }, min: 30, max: 100 }, plotoptions: { scatter: { marker: { radius: 5, states: { hover: { enabled: true, linecolor: 'rgb(100,100,100)' } } }, states: { hover: { marker: { enabled: false } } }, tooltip: { headerformat: '<b>{series.name}</b><br>', pointformat: '{point.x} f, {point.y} %rh' } }, series: [{ name: 'night', data: json(1) }, { name: 'night', data: json(2) }); }); }); }); </script>
thanks in advance!
the php file creating json data below. how separate these arrays comma?
$result1 = mysql_query("select round(avg(d_internal_duct_return),0) 'avg_return', round(avg(d_evap_pre_humidity),0) 'avg_hum' pheom.pheom_gb timestamp between subdate(curdate(), interval 2 month) , curdate() , hour(timestamp) not between 9 , 22 group day(timestamp) order timestamp"); $ret1 = array(); while($item = mysql_fetch_array($result1)) { $avg_return1 = $item['avg_return']; $avg_hum1 = $item['avg_hum']; $ret1[] = array($avg_return1,$avg_hum1); } $result2 = mysql_query("select round(avg(d_internal_duct_return),0) 'avg_return', round(avg(d_evap_pre_humidity),0) 'avg_hum' pheom.pheom_gb timestamp between subdate(curdate(), interval 2 month) , curdate() , hour(timestamp) between 9 , 22 group day(timestamp) order timestamp"); $ret2 = array(); while($item = mysql_fetch_array($result2)) { $avg_return2 = $item['avg_return']; $avg_hum2 = $item['avg_hum']; $ret2[] = array($avg_return2,$avg_hum2); } echo json_encode($ret1, json_numeric_check); echo json_encode($ret2, json_numeric_check);
not sure this, @ first glance think array returned php file requires additional square bracket outside in order parsed proper json. is:
[[65,44],[66,37]..][[75,36],[72,42]..]
from know, 2 arrays. want enclose these arrays within array. try changing to:
[[[65,44],[66,37]..],[[75,36],[72,42]..]]
that is, add square bracket outside , separate 2 arrays using comma.
in addition, here:
series: [{ name: 'night', data: json(1) }, { name: 'night', data: json(2) });
json(1) , json(2) interpreted function calls. should instead use:
series: [{ name: 'night', data: json[0] }, { name: 'night', data: json[1] });
edit ---- edited per op edits
also requested, in order add commas , proper formatting, php file can changed @ last 2 lines follows:
echo "[".json_encode($ret1, json_numeric_check).","; echo json_encode($ret2, json_numeric_check)."]";
Comments
Post a Comment