user1745767
user1745767

Reputation: 1071

HighCharts - making a Pie with MySQL and PHP

I'm trying to extend my usage of HighCharts and MySQL/PHP to the pie charts,

But I'm not sure how to add the series data.

My SQL query produces a table like:

group     value
south     34532
east      23411
west      23422
north     23421

Then I write the fetch_array (maybe my value is a string and should be int?)

while($row = mysql_fetch_array($result))
  {
extract($row);
        $data[] = "[$group, $value]";
        }
        mysql_close($connId);
    ?>

Then try to put the series into the HighCharts js:

series: [{
            type: 'pie',
            name: 'Test Data',
            data: [<?php echo '[' .join($data, ','). ']' ?>]
        }]

It doesn't produce a pie chart, no error, just blank DIV.

Upvotes: 1

Views: 4685

Answers (1)

user1745767
user1745767

Reputation: 1071

I solved it like this:

while($row = mysql_fetch_array($result))
{
extract($row);

    $datapie[] = array($group, intval($val));
        }
        mysql_close($connId);
        $data = json_encode($datapie);
    ?>

And the series JS data like:

series: [{
            type: 'pie',
            name: 'Test Data',
            data: <?php echo $data; ?>
        }]

Upvotes: 1

Related Questions