score:0

Simplest way is to query data from mySql and then sort it same as

[
        ['Firefox.com',   45.0],
        ['Default.com',       26.8],
        ['MSN',       12.8],
        ['Google.com',    8.5],
        ['Yahoo.com',     6.2],
        ['Others',   0.7]
     ]

Requires if you want to show chart just on page loading. You can also use JSON.

score:2

 series: [{
         type: 'pie',
         name: 'Browser share',
         data: [
         <?php

         $sql = 'select sum(hits) from tracks';
         $result = mysql_query($sql);
         $row = mysql_fetch_row($result);
         $totalHits = $row[0];

         $sql = 'select name, hits from tracks order by hits desc';
         $result = mysql_query($sql);

         $i = 0;
         $totalOther = 0;
         $maxSlices = 5;
         $minPercent = 10;

         while ($row = mysql_fetch_row($result))
         {
            $percent = row[1] / $totalHits * 100;

            if (++$i <= $maxSlices && $percent >= $minPercent)
            {
                echo json_encode($row);
            }
            else
            {
                $totalOther += $row[1];
            }
         }
         if ( $totalOther > 0 ) echo json_encode(array('Other', $totalOther));
         ?>
         ]
      }]

if you want to refresh it thourgh ajax...

...
series: [{
         type: 'pie',
         name: 'Browser share',
         data: getData(function(result) {return result;}),
...

and

function getData(setDataCallback)
{
    $.getJSON('file.php', args, function(result)  {  // use of jquery for clarity.
        setDataCallback(result);
    });
}

in php you have to do a new file ('file.php') with the code shown in the first code block;


Related Query

More Query from same tag