/* CAT:Scaling */ /* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(1700, 2500, 7800, 4500, 3150), "Distance"); $MyData->setAxisName(0, "Maximum distance"); $MyData->setAxisUnit(0, "m"); $MyData->setAxisDisplay(0, AXIS_FORMAT_METRIC); /* Create the abscissa serie */ $MyData->addPoints(array(1230768000, 1233446400, 1235865600, 1238544000, 1241136000, 1243814400), "Timestamp"); $MyData->setSerieDescription("Timestamp", "Sampled Dates"); $MyData->setAbscissa("Timestamp"); $MyData->setXAxisDisplay(AXIS_FORMAT_DATE); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 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, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "drawScale() - draw the X-Y scales", array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font */
$MyData = new pData(); $BaseTs = mktime(0, 0, 0, 12, 25, 2011); $LastIn = 0; $LastOut = 0; for ($i = 0; $i <= 1440; $i++) { $LastIn = abs($LastIn + rand(-1000, +1000)); $LastOut = abs($LastOut + rand(-1000, +1000)); $MyData->addPoints($LastIn, "Inbound"); $MyData->addPoints($LastOut, "Outbound"); $MyData->addPoints($BaseTs + $i * 60, "TimeStamp"); } $MyData->setAxisName(0, "Bandwidth"); $MyData->setAxisDisplay(0, AXIS_FORMAT_TRAFFIC); $MyData->setSerieDescription("TimeStamp", "time"); $MyData->setAbscissa("TimeStamp"); $MyData->setXAxisDisplay(AXIS_FORMAT_TIME, "H:00"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw a background */ $Settings = array("R" => 90, "G" => 90, "B" => 90, "Dash" => 1, "DashR" => 120, "DashG" => 120, "DashB" => 120); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_HORIZONTAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 11));
protected function render_graph($title, pData $MyData, $zoom, $width = 0, $height = 0) { // Check graph size sanity $width = intval($width); if ($width <= 50 || $width > 4096) { $width = 700; } $height = intval($height); if ($height <= 60 || $height > 4096) { $height = 260; } $MyData->setSerieDescription("TimeStamp", "time"); $MyData->setAbscissa("TimeStamp"); switch ($zoom) { case 'hour': $MyData->setXAxisDisplay(AXIS_FORMAT_TIME, "H:00"); break; case 'year': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y"); break; case 'month': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y-m"); break; case 'day': $MyData->setXAxisDisplay(AXIS_FORMAT_DATE, "Y-m-d"); break; } /* Create the pChart object */ $myPicture = new pImage($width, $height, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw a background */ $Settings = array("R" => 90, "G" => 90, "B" => 90, "Dash" => 1, "DashR" => 120, "DashG" => 120, "DashB" => 120); $myPicture->drawFilledRectangle(0, 0, $width, $height, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, $width, $height, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, $width, $height, DIRECTION_HORIZONTAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => AmpConfig::get('prefix') . "/modules/pChart/fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(150, 35, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => AmpConfig::get('prefix') . "/modules/pChart/fonts/pf_arma_five.ttf", "FontSize" => 6)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, $width - 20, $height - 50); /* Draw the scale */ $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 200, "GridG" => 200, "GridB" => 200, "RemoveSkippedAxis" => TRUE, "DrawSubTicks" => FALSE, "Mode" => SCALE_MODE_START0, "LabelRotation" => 45, "LabelingMethod" => LABELING_DIFFERENT); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; /* Draw the line chart */ $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $myPicture->drawLineChart(); /* Write a label over the chart */ $myPicture->writeLabel("Inbound", 720); /* Write the chart legend */ $myPicture->drawLegend(280, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); header("Content-Disposition: filename=\"ampache-graph.png\""); /* Render the picture (choose the best way) */ $myPicture->autoOutput(); }
function electrique_mois() { //initialisation des variables tableau $timestamp = ""; $conso = ""; $sql = mysql_query("SELECT TIMESTAMP(CONCAT(YEAR(date_histo ),'-',MONTH(date_histo ),'-',DAY(date_histo ),' ',HOUR(date_histo ),':00')),\n\t\t\t\t\tdate_histo, AVG(valeur1),MAX(valeur1),MIN(valeur1)\n\t\t\t\t\tFROM historique_donnees\n\t\t\t\t\tWHERE id_objet = 2\n\t\t\t\t\tAND date_histo > DATE_SUB(NOW( ), INTERVAL 31 DAY)\n\t\t\t\t\tGROUP BY YEAR( date_histo ) , MONTH( date_histo ) , DAY( date_histo ), HOUR( date_histo ), id_objet\n\t\t\t\t\tHAVING HOUR( date_histo ) IN ( 00, 06, 12, 18 ) \n\t\t\t\t\tORDER BY date_histo"); while (list($date_histo, $date_histo2, $conso_sql, $conso_sql_max, $conso_sql_min) = mysql_fetch_array($sql)) { $timestamp[] = strtotime($date_histo); $conso[] = $conso_sql; $conso_max[] = $conso_sql_max; $conso_min[] = $conso_sql_min; } $myData = new pData(); $myData->addPoints($timestamp, "Timestamp"); $myData->addPoints($conso, "Consommation Instantanée Moyenne"); $myData->addPoints($conso_max, "Conso. Inst. Max"); $myData->addPoints($conso_min, "Conso. Inst. Min"); $myData->setSerieOnAxis("Consommation Instantanée", 0); $myData->setSerieOnAxis("Conso. Inst. Max", 0); $myData->setSerieOnAxis("Conso. Inst. Min", 0); $myData->setAbscissa("Timestamp"); $myData->setXAxisName("Time"); $myData->setXAxisDisplay(AXIS_FORMAT_TIME, "d/m"); $myData->setAxisName(0, "Consommation Instantanée"); $myData->setAxisUnit(0, "W"); $myPicture = new pImage(1250, 550, $myData); $Settings = array("StartR" => 48, "StartG" => 124, "StartB" => 183, "EndR" => 33, "EndG" => 86, "EndB" => 128, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 1250, 550, DIRECTION_VERTICAL, $Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20)); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 18)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255); $myPicture->drawText(350, 25, "Consommation éléctrique", $TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(110, 50, 1160, 500); $myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $Settings = array("Pos" => SCALE_POS_LEFTRIGHT, "Mode" => SCALE_MODE_FLOATING, "LabelingMethod" => LABELING_ALL, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 45, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL, "LabelSkip" => 3); $myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); $Config = ""; $myPicture->drawSplineChart($Config); $Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/Forgotte.ttf", "FontSize" => 14, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL); $myPicture->drawLegend(563, 16, $Config); $myPicture->render("tmp/graphe_em.png"); echo "<img src='tmp/graphe_em.png' alt='graphe'/>"; }
/* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(1700, 2500, 7800, 4500, 3150), "Distance"); $MyData->setAxisName(0, "Maximum distance"); $MyData->setAxisUnit(0, "m"); $MyData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, "YAxisFormat"); /* Create the abscissa serie */ $MyData->addPoints(array(1230768000, 1233446400, 1235865600, 1238544000, 1241136000, 1243814400), "Timestamp"); $MyData->setSerieDescription("Timestamp", "Sampled Dates"); $MyData->setAbscissa("Timestamp"); $MyData->setAbscissaName("Dates"); $MyData->setXAxisDisplay(AXIS_FORMAT_CUSTOM, "XAxisFormat"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 700, 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, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "drawScale() - draw the X-Y scales", array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font */