Hello, I've noticed that using the library to process time values with the following format:
hh:mm:ss, the graph is not properly visualized.
Someone can tell me how to avoid this?
This is the code i have produced:
Code:
<?php
/* Library settings */
define("CLASS_PATH", "../../../class");
define("FONT_PATH", "../../../fonts");
/* pChart library inclusions */
include(CLASS_PATH."/pData.class.php");
include(CLASS_PATH."/pDraw.class.php");
include(CLASS_PATH."/pImage.class.php");
/* Create and populate the pData object */
$MyData = new pData();
//print "::pData";
$curData = date("Y-m-d");
/* Connect to the MySQL database */
$db = mysql_connect("localhost", "root", "password");
mysql_select_db("test",$db);
/* Build the query that will returns the data to graph */
$Requete = "SELECT * FROM test.eo_data WHERE uid=1 and data='".$curData."';";
//print $Requete;
$Result = mysql_query($Requete,$db);
//print $Result;
while($row = mysql_fetch_array($Result))
{
//print_r ($row);
/* Get the data from the query result */
if(strlen($ora)>0){
$ora = $ora.",".$row["ora"];
}else $ora = $row["ora"];
if(strlen($energia)>0){
$energia = $energia.",".$row["energia_conteggiata"];
}else $energia = $row["energia_conteggiata"];
if(strlen($fatpot)>0){
$fatpot = $fatpot.",".$row["fattore_potenza"];
}else $fatpot = $row["fattore_potenza"];
if(strlen($tens)>0){
$tens = $tens.",".$row["tensione"];
}else $tens = $row["tensione"];
}
/* Save the data in the pData array */
$MyData->addPoints(array($energia),"Energia Conteggiata");
$MyData->addPoints(array($fatpot),"Fattore Potenza");
$MyData->addPoints(array($tens),"Tensione");
$MyData->setYAxisName(0,"Dati");
/* Put the timestamp column on the abscissa axis */
$MyData->addPoints(array($ora),"Ore");
$MyData->setSerieDescription("Ore","Ora");
$MyData->setAbscissa("Ore");
//print "::Load done settings";
/* Create the pChart object */
$myPicture = new pImage(800,230,$MyData);
/* Retrieve the image map */
if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"]))
$myPicture->dumpImageMap("ImageMapBarChart",IMAGE_MAP_STORAGE_FILE,"pChartTest1","../tmp");
/* Set the image map name */
$myPicture->initialiseImageMap("ImageMapBarChart",IMAGE_MAP_STORAGE_FILE,"pChartTest1","../tmp");
/* Turn of Antialiasing */
$myPicture->Antialias = FALSE;
/* Draw the background */
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,800,230,$Settings);
/* Overlay with a gradient */
$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,799,230,DIRECTION_VERTICAL,$Settings);
/* Add a border to the picture */
$myPicture->drawRectangle(0,0,799,229,array("R"=>0,"G"=>0,"B"=>0));
/* Set the default font */
$myPicture->setFontProperties(array("FontName"=>FONT_PATH."/pf_arma_five.ttf","FontSize"=>6));
/* Define the chart area */
$myPicture->setGraphArea(60,40,799,200);
/* Draw the scale */
$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE);
$myPicture->drawScale($scaleSettings);
/* Write the chart legend */
$myPicture->drawLegend(600,12,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));
/* Turn on shadow computing */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
/* Draw the chart */
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$Settings = array("RecordImageMap"=>TRUE);
$myPicture->drawBarChart($Settings);
/* Render the picture (choose the best way) */
$myPicture->autoOutput("../tmp/pChartTest1.png");
?>
In particular i expected six bar related to two differents times.
Attached the graph produced!!
Another question, the data scale is automatically adjusted or are there any functions that i can use to do this?
Thank you
Marco