1

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.

Alain Collins
  • 16,268
  • 2
  • 32
  • 55
user1745767
  • 1,061
  • 2
  • 11
  • 16
  • Can you do a view source and see what javascript looks like on the client side and check that against the documentation of highcharts. Seems to me that you are echoing set of additional square brackets. – dakdad Oct 23 '12 at 03:06

1 Answers1

1

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; ?>
        }]
user1745767
  • 1,061
  • 2
  • 11
  • 16
  • yes json encode is the right way **always** check this too http://stackoverflow.com/questions/12520865/convert-mysql-resultset-into-a-name-data-object-to-be-fed-into-highcharts/12525219#12525219 – Jugal Thakkar Oct 23 '12 at 07:40