php - Flot pie chart get data from database -
hi trying retrieve data mysql database create flot pie, i've data looks this
data in array
$array = array();
$array[0] = array(); $array[1] = array(); $array[2] = array();
$array[0]['label'] = 'grade a'; $array[1]['label'] = 'grade b'; $array[2]['label'] = 'grade c';
$array[0]['color'] = '#89a54e'; $array[1]['color'] = '#aa4643'; $array[2]['color'] = '#4572a7';
$array[0]['data'][0] = array(1,700); $array[1]['data'][0] = array(1,500); $array[2]['data'][0] = array(1,600);
echo json_encode($array);
and mysql
$server = "localhost"; $user="root"; $password=""; $database = "db_test"; $connection = mysql_connect($server,$user,$password); $db = mysql_select_db($database,$connection); $query = "select * pie"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { $event_array[] = array( 'label' => $record['label'], 'color' => $record['color'], 'data' => $record['data'] ); } echo json_encode($event_array);
my flot js
$.ajax ({ type:'post', datatype: 'json', url:'data.php', success: function(data) { $.plot($('#pie'), data, { series: { pie: { show: true, innerradius: 0.4, radius: 1, label: { show: true, radius: 1, formatter: function(label, series) { return "<div style='font-size:11px; text-align:center; padding:2px; color:white;'>"+label+"<br/>" +math.round(series.percent)+"%</div>"; }, background: { opacity: 0.8 } } } }, grid: { hoverable: true }, legend: { show: false } }); } });
it won't display anything, can me.
Comments
Post a Comment