pChart 2.x forum http://wiki.pchart.net/forum/ |
|
Problem Retrieving Data from MySQL to generate chart http://wiki.pchart.net/forum/viewtopic.php?f=1&t=2596 |
Page 1 of 1 |
Author: | kore [ Wed Apr 04, 2012 9:03 pm ] |
Post subject: | Problem Retrieving Data from MySQL to generate chart |
Code: <?php /* Include the pData class */ include("pchart/class/pData.class.php"); include("pchart/class/pDraw.class.php"); include("pchart/class/pImage.class.php"); /* Create the pData object */ $myData = new pData(); /* Connect to the MySQL database */ $db = mysql_connect("host", "uname", "pass"); mysql_select_db("replies",$db); /* Build the query that will return the data to graph */ $query = "SELECT COUNT( * ) AS `Rows` , `Do you have an interest in Green IT` FROM `replies` LIMIT 0 , 30"; $Result = mysql_query($query,$db); $cpu=""; $Yes=""; $No=""; $Undecided=""; while($row = mysql_fetch_array($Result)) { /* Push the results of the query in an array */ $Yes[] = $row["Yes"]; $No[] = $row["No"]; $Undecided[] = $row["Undecided"]; } /* Save the data in the pData array */ $myData->addPoints($Yes,"Yes"); $myData->addPoints($No,"No"); $myData->addPoints($Undecided,"Undecided"); /* First Y axis will be dedicated to the responses */ $myData->setAxisName(0,"Responses"); /* Second Y axis will be dedicated to the number of responses */ $myData->setAxisName(1,"Number of Responses"); /* graphical output */ $myPicture = new pImage(500,500,$myData); $myPicture->drawGradientArea(0,0,500,500,DIRECTION_VERTICAL,array ("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>100)); $myPicture->drawGradientArea(0,0,500,500,DIRECTION_HORIZONTAL,array("StartR"=>240,"StartG"=>240,"StartB"=>240,"EndR"=>180,"EndG"=>180,"EndB"=>180,"Alpha"=>20)); $myPicture->setFontProperties(array("FontName"=>"pchart/fonts/pf_arma_five.ttf","FontSize"=>6)); /* Draw the chart scale */ $myPicture->setGraphArea(100,30,480,480); $myPicture->drawScale(array("CycleBackground"=>TRUE,"DrawSubTicks"=>TRUE,"GridR"=>0,"GridG"=>0,"GridB"=>0,"GridAlpha"=>10,"Pos"=>SCALE_POS_TOPBOTTOM)); /* Turn on shadow computing */ $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); /* Create the per bar palette */ $Palette = array("0"=>array("R"=>188,"G"=>224,"B"=>46,"Alpha"=>100), "1"=>array("R"=>224,"G"=>100,"B"=>46,"Alpha"=>100), "2"=>array("R"=>224,"G"=>214,"B"=>46,"Alpha"=>100), "3"=>array("R"=>46,"G"=>151,"B"=>224,"Alpha"=>100), "4"=>array("R"=>176,"G"=>46,"B"=>224,"Alpha"=>100), "5"=>array("R"=>224,"G"=>46,"B"=>117,"Alpha"=>100), "6"=>array("R"=>92,"G"=>224,"B"=>46,"Alpha"=>100), "7"=>array("R"=>224,"G"=>176,"B"=>46,"Alpha"=>100)); /* Draw the chart */ $myPicture->drawBarChart(array("DisplayPos"=>LABEL_POS_INSIDE,"DisplayValues"=>TRUE,"Rounded"=>TRUE,"Surrounding"=>30,"OverrideColors"=>$Palette)); /* Write the legend */ $myPicture->drawLegend(570,215,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.drawBarChart.palette.png"); ?> What am I doing wrong here? Please advise. Thanks in advance PS: My host is using hte latest release of mySQL and PHP with GD. Here's the result of what I've done: http://befoz.netau.net/charts.php as you can see the scale is wrong, and also there are no bars and no label numebr of responses. |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |