pChart 2.x forum http://wiki.pchart.net/forum/ |
|
problem with scale x axis and mysql data http://wiki.pchart.net/forum/viewtopic.php?f=1&t=29424 |
Page 1 of 1 |
Author: | pawnies20 [ Tue Jul 10, 2012 12:47 pm ] |
Post subject: | problem with scale x axis and mysql data |
Nevertheless, I have a little problem that I can not solve. I use a mysql database as a source of graphics. The x-axis contains the time (in hours on one day) and the y-axis temperatures But the datas in the database are not saved to fixed interval. So I have a graph that appears with the x-axis and at regular intervals such as 0 3 3 7 8 12 13 18 24 The scatter function seems to be the solution but I can not not do it! If you could give me a helping hand .... thank you My script: <?php /* Include the pData class */ include("pData.class.php"); include("pDraw.class.php"); include("pImage.class.php"); /* Create the pData object */ $MyData = new pData(); /* Connect to the MySQL database */ $db = mysql_connect("localhost", "root", "toto"); mysql_select_db("domotics",$db); /* Build the query that will returns the data to graph */ $Requete = "SELECT * FROM `EVENTS` where DEVICE ='^7' AND DATE >= DATE_SUB(current_date, INTERVAL 1 DAY) AND DATE < current_date ORDER BY DATE"; $Result = mysql_query($Requete ,$db); while($row = mysql_fetch_array($Result)) /* Get the data from the query result */ { $VALUE[] = $row["VALUE"]/10; /* $DATE[] = $row["DATE"];*/ $DATE[] = date("H.i", strtotime($row["DATE"]));} /* Save the data in the pData array */ $MyData->addPoints($DATE,"DATE"); $MyData->addPoints($VALUE,"VALUE"); $MyData->setScatterSerie("DATE","VALUE",0); /* insere les données de la colonne date en X */ $MyData->setAbscissa("DATE"); $myPicture = new pImage(796,370,$MyData,TRUE); $Settings = array("R"=>50,"G"=>70,"B"=>80,"Surrounding"=>0); /* remplissage du rectangle */ $myPicture->drawRoundedFilledRectangle(0,0,795,369,20,$Settings); /* lisere noir en contour */ $myPicture->drawRoundedRectangle(0,0,795,369,20, array("R"=>0,"G"=>0,"B"=>0)); $myPicture->drawFromPNG(250,-1,"c:\INETPUB/tempicon.png"); /* LEGENDE TITRE */ $myPicture->setFontProperties(array("FontName"=>"calibri.ttf","FontSize"=>22)); $TextSettings = array("DrawBox"=>false,"Align"=>TEXT_ALIGN_MIDDLEMIDDLE,"BoxRounded"=>TRUE,"R"=>0,"G"=>0,"B"=>0,"Angle"=>0,"FontSize"=>22); $myPicture->drawText(388,30,"- chambre Perrine -",$TextSettings); $myPicture->setShadow(false); $myPicture->setGraphArea(60,60,770,310); /* taille police valeurs abscisse et ordonnee */ $myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"calibri.ttf","FontSize"=>6)); /* permet de n'afficher qu'une heure sur 3 */ $myPicture->drawScale(array("CycleBackground"=>true,"LabelSkip"=>5,"DrawSubTicks"=>true,"LabelRotation"=>45)); $myPicture->setShadow(TRUE,array("X"=>2,"Y"=>2,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>30)); $myPicture->drawSplineChart(); /* Write a legend box */ $myPicture->setFontProperties(array("FontName"=>"calibri.ttf","FontSize"=>20)); /* Write some text */ $TextSettings = array("R"=>0,"G"=>0,"B"=>0,"Angle"=>0,"FontSize"=>16); $myPicture->drawText(150,355,"min :",$TextSettings); $myPicture->drawText(200,355,$MyData->getmin("VALUE"),$TextSettings); $myPicture->drawText(350,355,"max :",$TextSettings); $myPicture->drawText(400,355,$MyData->getmax("VALUE"),$TextSettings); $myPicture->drawText(550,355,"moy :",$TextSettings); $myPicture->drawText(600,355,$MyData->getSerieAverage("VALUE"),$TextSettings); /* Write a legend box */ $myPicture->setFontProperties(array("FontName"=>"calibri.ttf","FontSize"=>14)); $myPicture->drawLegend(665,18,array("R"=>85,"G"=>101,"B"=>109,"Surrounding"=>20,"Family"=>LEGEND_FAMILY_CIRCLE)); /* Render the picture */ $myPicture->Render("c:\INETPUB/temp.png"); ?> FRED |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |