lilman Posted November 27, 2006 Share Posted November 27, 2006 I would like to learn how to read results from a MySQL database and with it values create a pie graph. Could anyone be kind enough to point me into a direction where I could read on how to do this? Link to comment https://forums.phpfreaks.com/topic/28662-looking-for-a-direction-%E2%80%93-pie-graphphpmysql/ Share on other sites More sharing options...
Barand Posted November 28, 2006 Share Posted November 28, 2006 The angle for each slice is given by[pre] value ----------- * 360total value[/pre]Then you need to increment the start and end angles of each slice to create the pie[code]<?php$values = array(20, 30, 40); // values from your db$im = imagecreate(200,200);$bg = imagecolorallocate($im, 0, 0, 0);$colors = array( imagecolorallocate($im, 0xFF, 0, 0), //red imagecolorallocate($im, 0, 0xFF, 0), //green imagecolorallocate($im, 0, 0, 0xFF) //blue);$s_angle = 0; // pie slice start angle$e_angle = 0; // pie slice end angle$total = array_sum($values);$k = count($values);$cx = $cy = 100; // centre of the pie chartfor ($i=0; $i<$k; $i++) { $a = $values[$i] / $total * 360; // angle for this slice $e_angle += $a; imagefilledarc($im, $cx, $cy, 180, 180, $s_angle, $e_angle, $colors[$i], IMG_ARC_PIE); $s_angle += $a; // start angle for next slice}header ('content-type: image/png');imagepng($im);imagedestroy($im);?>[/code] Link to comment https://forums.phpfreaks.com/topic/28662-looking-for-a-direction-%E2%80%93-pie-graphphpmysql/#findComment-131243 Share on other sites More sharing options...
lilman Posted November 28, 2006 Author Share Posted November 28, 2006 Thank you... is there any place on the IE I could go to read up on how to graph data using PHP and MySQL. I am completely new to graphing, so what you showed me wasn't much help. Link to comment https://forums.phpfreaks.com/topic/28662-looking-for-a-direction-%E2%80%93-pie-graphphpmysql/#findComment-131373 Share on other sites More sharing options...
Barand Posted November 28, 2006 Share Posted November 28, 2006 try googling "php graph tutorial" and take your pick Link to comment https://forums.phpfreaks.com/topic/28662-looking-for-a-direction-%E2%80%93-pie-graphphpmysql/#findComment-131442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.