javascript - Multiple series data Highcharts line -


the result of query use display 3 column (country, date, items). php code side

 $res = db_query($sql); $dat = array();  while($r = db_fetch_array($res)){     $dat[]= array($r['date'], $r['items'], $r['country']); }  // armar $start_date = ''; if(count($dat)>0){     $s = split(' ',$dat[0][0]);     $ss = split('-',$s[0]); } // cada objeto en $dats es una grafica $dats[] = array('type'=>'line',             'name'=>$q['title'],             'pointinterval'=>24 * 3600 * 1000,             'pointstart'=>mktime(0,0,0,$ss[1],$ss[2],$ss[0])*1000,             'data'=>$dat) ; //echo "$sql"; echo json_encode($dats,json_numeric_check); 

my javascript code :

function loadline(_data){     $('#line_container').highcharts({         chart: {zoomtype: 'x',spacingright: 20},         title: { text: 'monthly created items'},         subtitle: {text:'updated every day'},         xaxis: {             type: 'datetime',             maxzoom: 7 * 24 * 3600000, // fourteen days             title: {text: null}         },         yaxis: {title: {text: 'created items'}},         tooltip: {shared: true},         legend: {enabled: true},         plotoptions: {             area: {                 fillcolor: {                     lineargradient: { x1: 0, y1: 0, x2: 0, y2: 1},                     stops: [                         [0, highcharts.getoptions().colors[0]],                         [1, highcharts.color(highcharts.getoptions().colors[0]).setopacity(0).get('rgba')]                     ]                 },                 linewidth: 1,                 marker: {                     enabled: false                 },                 shadow: false,                 states: {                     hover: {                         linewidth: 1                     }                 },                 threshold: null             }         },         series: _data     }); }  

and result displayed enter image description here

how change "series 1" in graph country name receive in query? data have in query has date until "april" (ytd) graph shows months in future, how correct this? if have more 1 country in query how display in multiple chart lines @ same time. in advance.

you have supplied single series, translate single line. try like:

 $res = db_query($sql); $dat = array();  while($r = db_fetch_array($res)){     if (!isset($dat[$r['country']]))         $dat[$r['country']] = [];      $dat[$r['country']][] = array($r['date'], $r['items'], $r['country']); }  // armar $start_date = ''; if(count($dat)>0){     $s = split(' ',$dat[0][0]);     $ss = split('-',$s[0]); } // cada objeto en $dats es una grafica $dats = []; foreach ($dat $country => $values) { $dats[] = array('type'=>'line',             'name'=>$q['title'],             'pointinterval'=>24 * 3600 * 1000,             'pointstart'=>mktime(0,0,0,$ss[1],$ss[2],$ss[0])*1000,             'data'=>$values) ; } //echo "$sql"; echo json_encode($dats,json_numeric_check); 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -