Highcharts add several series with PHP array -
i'm using highcharts display database informations, when use 1 series haven't problems, when want add several series on chart, it's little bit difficult.
first php script :
foreach ($informationslier $keyfille => $fille) { $grafdata = array(); foreach ($fille['information'] $keyinfos => $information) { $mois = $information['created']->format('m'); $mois = $mois - 1; $timestamp = strtotime($information['created']->format('j').'-'.$mois.'-'.$information['created']->format('y')); //multiply 1000 seconds in js $timestamp = $timestamp * 1000; $grafdata[$keyinfos] = array($timestamp, (float)$information['valeur']); //$grafdata[$keyinfos] = implode(', ', $grafdata[$keyinfos]); //$grafdata[] = "[date.utc(".$information['created']->format('y').','.$mois.','.$information['created']->format('j')."),".$information['valeur']."]"; } $tabinformationsdata[$keyfille]['name'] = 'evolution '.$fille['titre']; $tabinformationsdata[$keyfille]['color'] = '#ffa020'; //$tabinformationsdata['infos'][$keyfille]['data'] = array(); //$implodegraf = implode(',', $grafdata); $tabinformationsdata[$keyfille]['data'] = $grafdata; }
the php script return me :
array ( [0] => array ( [name] => evolution pourcentage [color] => #ffa020 [data] => array ( [0] => array ( [0] => 1451084400000 [1] => 17.00 ) [1] => array ( [0] => 1451170800000 [1] => 19.00 ) [2] => array ( [0] => 1451257200000 [1] => 14.00 ) [3] => array ( [0] => 1451343600000 [1] => 6.00 ) ) ) )
i send array view , :
series: {{ graphique | json_encode() | raw }},
but in html, rendering looks , doesn't work :
series: [{ "name":"evolution pourcentage", "color":"#ffa020", "data":[[1451084400000,"17.00"],[1451170800000,"19.00"],[1451257200000,"14.00"],[1451343600000,"6.00"]] }],
i don't know why doesn't work... try multiply 1000 timestamp or not nothing work. so, how can display series ?
edited
work passing date timestamp , adding (float) before values... edited post response.
thanks
perhaps
- iterate on
{{ my_array }}
twig variable - use unicode character json : json specification
Comments
Post a Comment