javascript - Populating highcharts with php via json_encode -


i have been wrestling highcharts , json_encode via php few days now. believe have data formatted yet chart not updating properly. category data updated , series data chart column , line data formatted should be.

can me rest of way. here php script , highcharts javascript using.

thank help:

<?php           // data feed power dynamic charts include_once('db_conn.php');  // site data , store in array $query = mysql_query("select site, sum(impressions) impressions, sum(clicks)     clicks dfa_data campaign='$campaign' , time='$time' group site order   impressions desc"); $rows = array(); while($r = mysql_fetch_array($query)) {     $rows['categories'][] = $r['site']; }  // impression data , store in array $query = mysql_query("select site, sum(impressions) impressions, sum(clicks) clicks dfa_data campaign='$campaign' , time='$time' group site order    impressions desc"); $rows1 = array(); $rows1['name'] = 'impressions'; $rows1['color'] = '#4572a7'; $rows1['type'] = 'column'; $rows1['yaxis'] = 1; while($rr = mysql_fetch_array($query)) {     $rows1['data'][] = $rr['impressions']; }  // ctr data , store in array $query = mysql_query("select site, sum(impressions) impressions, sum(clicks) clicks dfa_data campaign='$campaign' , time='$time' group site order impressions desc"); $rows2 = array(); $rows2['name'] = 'ctr'; $rows2['color'] = '#89a54e'; $rows2['type'] = 'spline'; while($rrr = mysql_fetch_array($query)) {  $ctr = number_format(($rrr['clicks']/$rrr['impressions'])*(100),2,'.',',');  $impressions = number_format($rrr['impressions'],0,'.',',');  $clicks = number_format($rrr['clicks'],0,'.',',');     $rows2['data'][] = $ctr; }  $result = array(); $result1 = array(); array_push($result,$rows); array_push($result1,$rows1); array_push($result1,$rows2);   ?>  <script> $(function () {      $('#container').highcharts({         chart: {             zoomtype: 'xy'         },         title: {             text: 'performance site'         },         subtitle: {             text: ''         },         xaxis:          <?php echo json_encode($result); ?>         ,         yaxis: [{ // primary yaxis             labels: {                 format: '{value}%',                 style: {                     color: '#89a54e'                 }             },             title: {                 text: 'ctr',                 style: {                     color: '#89a54e'                 }             }         }, { // secondary yaxis             title: {                 text: 'impressions',                 style: {                     color: '#4572a7'                 }             },             labels: {                 format: '{value}',                 style: {                     color: '#4572a7'                 }             },             opposite: true         }],         tooltip: {             shared: true         },         series: <?php echo json_encode($result1); ?>      });   }); </script> 

var_dump($result) outputs following

array(1) { [0]=> array(1) { ["categories"]=> array(5) { [0]=> string(13) "search medica" [1]=> string(10) "medscape 4" [2]=> string(11) "onclive.com" [3]=> string(22) "oncology nurse advisor" [4]=> string(25) "chemotherapyadvisor.com 1" } } } 

var_dump($result1) outputs following

string(7) "result1" 

here json_encode output both:

json_encode $result

[{"categories":["search medica","medscape 4","onclive.com","oncology nurse advisor","chemotherapyadvisor.com 1"]}] 

json_encode $result1

[{"name":"impressions","color":"#4572a7","type":"column","yaxis":1,"data":[140521,71905,69295,68456,49487]},{"name":"ctr","color":"#89a54e","type":"spline","data":[0.11,0.04,0.2,0.09,0.05]}] 

as see problem getting data ajax or similar, because when paste json (which looks fine) works http://jsfiddle.net/6fzcz/ advice take @ console, if receive errors. morever php file @ same server script chart?

$('#container').highcharts({     chart: {         type: 'line',         marginright: 10     },     xaxis: [{         "categories": ["search medica", "medscape 4", "onclive.com", "oncology nurse advisor", "chemotherapyadvisor.com 1"]     }],     series: [{         "name": "impressions",             "color": "#4572a7",             "type": "column",         //"yaxis": 1,         "data": [140521, 71905, 69295, 68456, 49487]     }, {         "name": "ctr",             "color": "#89a54e",             "type": "spline",             "data": [0.11, 0.04, 0.2, 0.09, 0.05]     }] }); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -