0 ORDER BY t1.DateTime ASC;"; $Result = mysql_query($Requete,$db); $date=""; $datetime=""; $time=""; $daytotal=""; $currentpower=""; while($row = mysql_fetch_array($Result)) { /* Push the results of the query in an array */ $datetime[] = $row["DateTime"]; $time[] = $row["TIME"]; $daytotal[] = $row["DayTotal"]; $currentpower[] = $row["CurrentPower"]; } /* Save the data in the pData array */ $MyData->addPoints($datetime,"Date Time"); $MyData->addPoints($time,"Time"); $MyData->addPoints($daytotal,"Day Total"); $MyData->addPoints($currentpower,"Current Power"); $chartDate = strftime("%d-%m-%Y %H:%M", strtotime($MyData->getMin("Date Time"))). " - ". strftime("%H:%M", strtotime($MyData->getMax("Date Time"))); $maxPower = $MyData->getMax("Current Power"); $maxDayTotal = round($MyData->getMax("Day Total") / 1000); $MyData->setAbscissa("Time"); /* Associate the "Day Total" data serie to the second axis */ $MyData->setSerieOnAxis("Day Total", 1); /* Name this axis "Time" */ $MyData->setXAxisName("Time"); /* First Y axis will be dedicated to the current power */ $MyData->setAxisName(0,"Power"); $MyData->setAxisUnit(0,"Watt"); $MyData->setAxisPosition(0,AXIS_POSITION_LEFT); /* Second Y axis will be dedicated to Day Total */ $MyData->setAxisName(1,"Energy"); $MyData->setAxisUnit(1,"Wh"); $MyData->setAxisPosition(1,AXIS_POSITION_RIGHT); $MyData->setAxisDisplay(1,AXIS_FORMAT_METRIC); /* Create a pChart object and associate your dataset */ $myPicture = new pImage(1000,500,$MyData); /* Add a border to the picture */ $myPicture->drawRectangle(0,0,1000,500,array("R"=>0,"G"=>0,"B"=>0)); /* Draw the scale */ $myPicture->setFontProperties(array( "FontName"=>"pChart/fonts/verdana.ttf", "FontSize"=>10)); $myPicture->setGraphArea(100,100,850,460); $ScaleSettings = array("XMargin"=>10, "YMargin"=>10, "Floating"=>TRUE, "DrawSubTicks"=>FALSE, "CycleBackground"=>FALSE, "LabelSkip"=>10, "Mode"=>SCALE_MODE_START0); $myPicture->drawScale($ScaleSettings); /* Graph title */ $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); $myPicture->drawText(50,52,"Daily Production ".$chartDate,array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMLEFT)); /* Draw the area chart chart */ $myPicture->setFontProperties(array( "FontName"=>"pChart/fonts/verdana.ttf", "FontSize"=>8)); $MyData->setSerieDrawable("Date Time",FALSE); $MyData->setSerieDrawable("Current Power",FALSE); $MyData->setSerieDrawable("Day Total",TRUE); $serieSettings = array("R"=>0, "G"=>204, "B"=>0, "Alpha"=>50); $MyData->setPalette("Day Total",$serieSettings); $myPicture->drawFilledSplineChart(); /* Draw the line and plot chart */ $MyData->setSerieDrawable("Current Power",TRUE); $MyData->setSerieDrawable("Day Total",FALSE); $MyData->setSerieWeight("Current Power",1); $MyData->setSerieWeight("Day Total",1); $serieSettings = array("R"=>0, "G"=>204, "B"=>0, "Alpha"=>100); $MyData->setPalette("Current Power",$serieSettings); $myPicture->drawSplineChart(); /* Make sure all series are drawable before writing the scale */ $MyData->setSerieDrawable("Day Total",TRUE); $myPicture->drawThreshold($maxPower,array( "WriteCaption"=>FALSE, "Caption"=>"Max", "Alpha"=>70, "Ticks"=>2, "R"=>0, "G"=>0, "B"=>255)); /* Write the legend */ /* $myPicture->drawLegend(540,35,array("Style"=>LEGEND_ROUND, "Alpha"=>20, "Mode"=>LEGEND_HORIZONTAL)); */ /* Write the 1st data series statistics */ $Settings = array( "R"=>0, "G"=>0, "B"=>0, "Align"=>TEXT_ALIGN_BOTTOMLEFT); $myPicture->drawText(50,500, "Max: ".ceil($MyData->getMax("Current Power"))." Watt, ". "Min: ".ceil($MyData->getMin("Current Power"))." Watt, ". "Avg: ".ceil($MyData->getSerieAverage("Current Power"))." Watt, ". "Total : ".round($MyData->getMax("Day Total")/1000,4)." kWh.",$Settings); /* Render the picture (choose the best way) */ $myPicture->autoOutput("images/sma_".$select_date.".png"); ?>