javascript - modify Xaxis in highcharts -


how can introduce in highcharts code array comes php code?

in next code php generate 4 arrays, 3 data (tmax ($rows), tmin ($rows1) , rain ($rows2) , last 1 days of consulting ($dia).

$sth = mysqli_query($con,"select city,tmax, day(date) dia meteo2 city= '" . $_session["city"] ."' , data between '" . split($_session["date8"]) ."' , '" . split($_session["date9"]) ."'order date");  $rows = array(); $dia = array(); $dia['name'] = 'dia'; $rows['name'] = 'tmax';  $rows['color'] = '#ff0000'; $cont=1; while($r = mysqli_fetch_array($sth)) { $rows['data'][] = $r['tmax']; $dia['categories'][] = $r['dia']; } $sth = mysqli_query($con,"select city,tmin meteo2 city= '" .   $_session["city"] ."' , data between '" . split($_session["date8"]) ."' , '" . split($_session["date9"]) ."'order date");  $rows1 = array(); $rows1['name'] = 'tmin'; $rows1['color'] = '#00ffff'; $rows1['var valuesuffix'] = 'Âșc'; while($rr = mysqli_fetch_assoc($sth)) { $rows1['data'][] = $rr['tmin']; }  mysqli_query($con,"select city,rain meteo2 city= '" . $_session["city"] ."' , data between '" . split($_session["date8"]) ."' , '" . split($_session["date9"]) ."'order date");  $rows2 = array(); $rows2['name'] = 'rain'; $rows2['type'] = 'column'; $rows2['color'] = '#4572a7'; $rows2['var valuesuffix'] = 'mm'; $rows2['var yaxis'] = 2; while($rr = mysqli_fetch_assoc($sth)) { $rows2['data'][] = $rr['rain']; }  $result = array(); array_push($result,$rows2); array_push($result,$rows1); array_push($result,$rows); array_push($result,$dia); print json_encode($result, json_numeric_check);   mysqli_close($con); ?> 

when plot chart, can see line of rain, tmax, tmin, in xaxis default have 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15....and need information of $dia inside categories[]

and when check browser see categories empty... xaxis: { categories: [] },

but in highchart code have

xaxis: { categories: ['<?php echo $dia?>'] }, 

any please????

here show highcharts code

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>www.meteo4u.com/consultanouformat.html</title>  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <script type="text/javascript"> <?php $city = $_post["city"];   session_start(); $_session['city'] = $_post['city']; $_session['date8'] = $_post['date8']; $_session['date9'] = $_post['date9']; ?>   $(function () { var chart;  $(document).ready(function() { $.getjson("mysql-highcharts.php", function(json) {  chart = new highcharts.chart({ chart: { renderto: 'container', type: 'spline', marginright: 130, marginbottom: 25 }, title: { text: 'temperatura maxima, temperatura minima precipitacio <?php echo $city ?>', x: -20 //center }, xaxis: { categories:  [<?php echo $dia?>] }, yaxis: [{ labels: { format: '{value}°c', style: { color: '#ff0000' } }, title: { text: 'temperatura maxima', style: { color: '#ff0000' } } },{title: { text: 'temperatura minima', style: { color: '#00ffff' } } },{labels: { format: '{value} mm', style: { color: '#4572a7' } }, title: { text: 'precipitacio', style: { color: '#4572a7' } },opposite: true }], tooltip: { formatter: function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; } }, legend: { layout: 'vertical', align: 'right', verticalalign: 'top', x: -10, y: 100, borderwidth: 0 }, credits:{ text: 'meteo4u.com', href:'http://meteo4u.com', itemstyle: {     fontsize: '40px' } }, series: json }); }); }); }); </script> </head> <body> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div> </body> </html> 

it looks $dia array array, containing entry called 'categories'. don't think can somply echo array variable in highcharts code, dia exists in php on server. returning categories inside json object in 3rd entry of array

array_push($result,$dia); 

this means have read categories out of returned json in highcharts code. code hard follow, try this:

xaxis: {     categories:  json[3]['categories']; }, 

however, worried line:

series: json 

the returned json not contain series definitions contains categories well. may work, not clean code.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -