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