|
|
Page 1 of 1
|
[ 3 posts ] |
|
How to reduce the output of Pchart
Author |
Message |
kore
New pChart user
Joined: Wed Apr 04, 2012 6:02 pm Posts: 2
|
How to reduce the output of Pchart
Code: <?php /* CAT:Bar Chart */
/* pChart library inclusions */ include("pchart/class/pData.class.php"); include("pchart/class/pDraw.class.php"); include("pchart/class/pImage.class.php");
/* Create and populate the pData object */ $myData = new pData(); $myData->setAxisName(0,"Number of Responses"); $myData->setSerieDescription("Types of Responses","Types of Responses"); $myData->setAbscissa("Types of Responses"); $myData->setAbscissaName("Types of Responses");
/* Connect to the MySQL database */
$db = mysql_connect("mysql7.000webhost.com", "a4728588_junaid", "pushmein01"); mysql_select_db("a4728588_replies",$db);
/* Build the query that will returns the data to graph */
$Requete = "SELECT `Do you have an interest in Green IT` AS resp, COUNT(*) AS num FROM 'replies' GROUP BY resp";
$Result = mysql_query($Requete,$db);
while($row = mysql_fetch_array($Result))
{ $myData->addPoints(array($row['resp'], $row['num'])); }
/* Create the pChart object */ $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"); ?>
I am having trouble making the mysql data retrieve the data so it only displays unique results - instead it seems to duplicate the results several times, or show nothing for several enteries if that makes sense.
|
Sun Apr 08, 2012 3:41 am |
|
|
rom
pChart user
Joined: Wed Sep 21, 2011 8:45 am Posts: 4
|
Re: How to reduce the output of Pchart
Hello, first: remove your mysql connection data from your post. second: You dont add all value pairs one by one. You build arrays with all the data. One for each graph (shown on vertical axis) and one for the horizontal axis (time stamps etc.) Code: while($row = mysql_fetch_array($Result)) { $values_h[] = $row['resp']; $values_v[] = $row['num']; } // all your curves here (values for vertical axis) $myData->addPoints(array($values_v, "numbers")); // 'numbers' is the label for the curve // $myData->addPoints(array($values_v2, "numbers 2")); // second curve // $myData->addPoints(array($values_v3, "numbers 3")); // third curve // ...
// now the values for the horizontal axis: $myData->addPoints(array($values_h, "timestamp")); $myData->setSerieDescription("timestamp","date / time"); $myData->setAbscissa("timestamp");
Something like that.
|
Tue Apr 24, 2012 2:01 pm |
|
|
seltzerchuck
New pChart user
Joined: Fri May 18, 2012 8:41 am Posts: 1
|
Where else could anyone get that kind of information in such a perfect way of writing and i was looking for more info.
_________________ Online GED
|
Fri May 18, 2012 9:08 am |
|
|
|
Page 1 of 1
|
[ 3 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 37 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|
|