Pass MySQL result to Highcharts

0

I have the following array, and I need to convert it to Highcharts interpret and generate the graph, how can I iterate my array, since it returns the duplicate region but with different sale value?

Where the X-axis would be [name], the name would be [nomreg] and date would be an array with [valven], follow Highcharts format, and array returned by PHP:

xAxis: {
    categories: ['Outros', 'Peças', 'Tratores'],
    crosshair: true
}


series: [{
    name: 'PR',
    data: [
        49.9, 71.5, 500
    ]
  }, {
    name: 'SC',
    data: [
        83.6, 78.8, 63
    ]

}]



Array (
[0] => stdClass Object
    (
        [anomes] => 201601
        [codreg] => 41
        [nomreg] => PR
        [codcin] => 1
        [nomcin] => OUTROS
        [valven] => 6835.7000
        [qtdven] => 1078.8000
    )

[1] => stdClass Object
    (
        [anomes] => 201601
        [codreg] => 42
        [nomreg] => SC
        [codcin] => 1
        [nomcin] => OUTROS
        [valven] => 3129.0000
        [qtdven] => 366.6200
    )

[2] => stdClass Object
    (
        [anomes] => 201601
        [codreg] => 42
        [nomreg] => SC
        [codcin] => 2
        [nomcin] => PECAS
        [valven] => 346.9100
        [qtdven] => 73.6600
    )

)

SQL result:

anomes  codreg  nomreg  codcin  nomcin     valven     qtdven  
------  ------  ------  ------  ------  ---------  -----------
201601      41  PR           1  OUTROS  6835.7000    1078.8000
201601      42  SC           1  OUTROS  3129.0000     366.6200
201601      42  SC           2  PECAS    346.9100      73.6600

Currently it looks like this:  

AndIwouldlikemycharttolooklikethis:

The chart will show sales by Region, and rank for a given year.

    
asked by anonymous 13.08.2018 / 14:27

1 answer

1

Hi @wribeiro, From what I saw in print, we'll see if we mount properly:

  • You need to get the while in the while:

    php:

    while ($row = mysqli_fetch_array($query)){
    
       $nomreg = $row['nomreg'];
       $valven = $row['valven'];
    
       $nomreg_chart []= $nomreg;
       $valven_chart_pecs []= $valven; 
       $valven_chart_outros []= $valven;
    
    }
    
    //$nomreg_chart_join = join($nomreg_chart,",");
      $nomreg_chart_join = "'".implode("','",$nomreg_chart)."'";
      $valven_chart_pecs_join = join($valven_chart,",");
      $valven_chart_outros_join = join($valven_chart,",");  
    
    
    aplicando no highchart:
    
     xAxis: {
            categories: [<?php echo $nomreg_chart_join; ?>],
            crosshair: true
        },
    

    series: [{     name: 'Parts',     date: [              ]   }, {     name: 'Other',     date: [              ]

    }]

  • Create two sqls, where one is filtering with where "others", and where "pieces".

13.08.2018 / 14:52