/* 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"; include CLASS_PATH . "/pStock.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(35, 28, 17, 27, 12, 12, 20, 15, 20, 28), "Open"); $MyData->addPoints(array(20, 17, 25, 20, 25, 23, 16, 29, 26, 17), "Close"); $MyData->addPoints(array(10, 11, 14, 11, 9, 4, 3, 7, 9, 5), "Min"); $MyData->addPoints(array(37, 32, 33, 29, 29, 25, 22, 34, 29, 31), "Max"); $MyData->addPoints(array(30, 20, 21, 24, 22, 18, 18, 24, 22, 24), "Median"); $MyData->setAxisDisplay(0, AXIS_FORMAT_CURRENCY, "\$"); $MyData->addPoints(array("Dec 13", "Dec 14", "Dec 15", "Dec 16", "Dec 17", "Dec 20", "Dec 21", "Dec 22", "Dec 23", "Dec 24"), "Time"); $MyData->setAbscissa("Time"); $MyData->setAbscissaName("Time"); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Retrieve the image map */ if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"])) { $myPicture->dumpImageMap("ImageMapStockChart", IMAGE_MAP_STORAGE_FILE, "StockChart", "../tmp"); } /* Set the image map name */ $myPicture->initialiseImageMap("ImageMapStockChart", IMAGE_MAP_STORAGE_FILE, "StockChart", "../tmp"); /* Turn of AAliasing */ $myPicture->Antialias = FALSE; /* Draw the border */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
<?php /* 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));
include "../class/pDraw.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $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 */
protected function buildCostPerKmChartData($cd = array()) { if (!$cd) { $cd = parent::buildCostPerKmChartData(); } if (!$cd) { return $cd; } $this->setOption('title', $cd['title']); $myData = new pData(); $x_id = $cd['x']['id']; $myData->addPoints($cd['x']['values'], $x_id); $myData->setAxisName(0, $cd['x']['description']); $myData->setAxisXY(0, AXIS_X); $myData->setAxisPosition(0, AXIS_POSITION_BOTTOM); $is_date = $this->getParameter('range_type') == 'date' ? true : false; $display_mode = $is_date ? AXIS_FORMAT_DATE : AXIS_FORMAT_DEFAULT; $display_format = $is_date ? 'd-M-Y' : null; $myData->setAxisDisplay(0, $display_mode, $display_format); foreach ($cd['y']['series'] as $key => $serie) { $values = $this->filterNulls($cd['y']['series'][$key]['values']); if (!$values) { continue; } $y_id = $cd['y']['series'][$key]['id']; $myData->addPoints($values, $y_id); $myData->setSerieOnAxis($y_id, 1); $myData->setScatterSerie($x_id, $y_id, $key); $myData->setScatterSerieDescription($key, $cd['y']['series'][$key]['label']); $myData->setScatterSerieWeight($key, 0.7); } $myData->setAxisName(1, $cd['y']['description']); $myData->setAxisXY(1, AXIS_Y); $myData->setAxisPosition(1, AXIS_POSITION_LEFT); return $myData; }
<?php /* 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_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 */
/* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(4, VOID, VOID, 12, 8, 3), "Probe 1"); $MyData->addPoints(array(3, 12, 15, 8, 5, 5), "Probe 2"); $MyData->addPoints(array(2, 7, 5, 18, 19, 22), "Probe 3"); $MyData->setPalette("Probe 1", array("R" => 220, "G" => 60, "B" => 20)); $MyData->setSerieTicks("Probe 2", 4); $MyData->setSerieWeight("Probe 3", 2); $MyData->setAxisName(0, "Temperatures"); $MyData->addPoints(array("Jan", "Feb", "Mar", "Apr", "May", "Jun"), "Labels"); $MyData->setSerieDescription("Labels", "Months"); $MyData->setAbscissa("Labels"); /* Reverse the Y axis trick */ $MyData->setAbsicssaPosition(AXIS_POSITION_TOP); $MyData->NegateValues(array("Probe 1", "Probe 2", "Probe 3")); $MyData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, "NegateValues"); function NegateValues($Value) { if ($Value == VOID) { return VOID; } else { return -$Value; } } /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); /* Turn of Antialiasing */ $myPicture->Antialias = FALSE; /* Draw a background */ $Settings = array("R" => 190, "G" => 213, "B" => 107, "Dash" => 1, "DashR" => 210, "DashG" => 223, "DashB" => 127); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings);
function GetGraphImageTag($_data, $_texts, $_metric = true) { if (!StatisticProvider::$DrawChartImages || !function_exists("gd_info")) { return ""; } require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pData.class.php"; require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pDraw.class.php"; require_once LIVEZILLA_PATH . "_lib/trdp/pchart/class/pImage.class.php"; $MyData = new pData(); $dobject = array(); foreach ($_data as $obid => $values) { foreach ($values as $key => $val) { $values[$key] = round($val, 1); } $dv1[] = $values[0]; if (count($values) > 1) { $dv2[] = $values[1]; } if (count($values) > 2) { $dv3[] = $values[2]; } if (count($values) > 3) { $dv4[] = $values[3]; } $dobject[] = $obid; if (count($dobject) == 5) { break; } } $MyData->addPoints($dv1, $_texts[1] . " "); if (isset($dv2)) { $MyData->addPoints($dv2, $_texts[2] . " "); } if (isset($dv3)) { $MyData->addPoints($dv3, $_texts[3] . " "); } if (isset($dv4)) { $MyData->addPoints($dv4, $_texts[4] . " "); } $MyData->setAxisName(0, $_texts[0]); $MyData->setAxisDisplay(0, $_metric ? AXIS_FORMAT_METRIC : AXIS_FORMAT_RAW); $MyData->addPoints($dobject, "Groups"); $MyData->setSerieDescription("Groups", "Group"); $MyData->setAbscissa("Groups"); $myPicture = new pImage(630, 210, $MyData); $myPicture->Antialias = FALSE; $myPicture->setFontProperties(array("FontName" => LIVEZILLA_PATH . "_lib/trdp/pchart/fonts/arimo.ttf", "FontSize" => 8, "R" => 120, "G" => 120, "B" => 120)); $myPicture->setGraphArea(46, 0, 620, 160); $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "YMargin" => 12, "CycleBackground" => TRUE); $myPicture->drawScale($scaleSettings); $myPicture->drawLegend(40, 190, array("Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL, "BoxSize" => 4, "R" => 200, "G" => 200, "B" => 200, "Surrounding" => 20, "Alpha" => 30)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $settings = array("Surrounding" => -30, "InnerSurrounding" => 30, "DisplayValues" => TRUE); $myPicture->drawBarChart($settings); $file = PATH_STATS . $this->Type . "/temp.png"; $myPicture->render($file); return "<img src=\"data:image/png;base64," . IOStruct::ToBase64($file) . "\" />"; }
<?php /* CAT:Scatter chart */ /* pChart library inclusions */ include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pImage.class.php"; include "../class/pScatter.class.php"; /* Create the pData object */ $myData = new pData(); /* Create the X axis and the binded series */ $myData->addPoints(array(3, 12, 15, 8, 5, -5), "X Values"); $myData->setAxisName(0, "X Values"); $myData->setAxisXY(0, AXIS_X); $myData->setAxisDisplay(0, AXIS_FORMAT_TIME, "i:s"); $myData->setAxisPosition(0, AXIS_POSITION_BOTTOM); /* Create the Y axis and the binded series */ $myData->addPoints(array(2, 7, 5, 18, 19, 22), "Y Values"); $myData->setSerieOnAxis("Y Values", 1); $myData->setAxisName(1, "Y Values"); $myData->setAxisXY(1, AXIS_Y); /* Create the pChart object */ $myPicture = new pImage(400, 400, $myData); /* Draw the background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 400, 400, $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, 400, 400, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 400, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Write the picture title */
function pch_threshold_graph($graph_type, $index, $data, $width, $height, $font, $antialiasing, $xaxisname = "", $yaxisname = "", $title = "", $show_values = false, $show_legend = false, $font_size) { /* CAT:Threshold Chart */ /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($data, "DEFCA"); $MyData->setAxisName(0, $yaxisname); $MyData->setAxisDisplay(0, AXIS_FORMAT_CURRENCY); $MyData->addPoints($index, "Labels"); $MyData->setSerieDescription("Labels", $xaxisname); $MyData->setAbscissa("Labels"); $MyData->setPalette("DEFCA", array("R" => 55, "G" => 91, "B" => 127)); /* Create the pChart object */ $myPicture = new pImage(700, 230, $MyData); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, array("StartR" => 220, "StartG" => 220, "StartB" => 220, "EndR" => 255, "EndG" => 255, "EndB" => 255, "Alpha" => 100)); $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 200, "G" => 200, "B" => 200)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size)); $myPicture->drawText(60, 35, $title, array("FontSize" => $font_size, "Align" => TEXT_ALIGN_BOTTOMLEFT)); /* Do some cosmetic and draw the chart */ $myPicture->setGraphArea(60, 40, 670, 190); $myPicture->drawFilledRectangle(60, 40, 670, 190, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -200, "Alpha" => 10)); $myPicture->drawScale(array("GridR" => 180, "GridG" => 180, "GridB" => 180, "Mode" => SCALE_MODE_START0)); $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size)); $settings = array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayValues" => $show_values, "DisplayZeroValues" => FALSE, "DisplayR" => 100, "DisplayG" => 100, "DisplayB" => 100, "DisplayShadow" => TRUE, "Surrounding" => 5, "AroundZero" => FALSE); $myPicture->drawSplineChart($settings); $myPicture->setShadow(FALSE); if ($show_legend) { /* Write the chart legend */ $myPicture->drawLegend(643, 210, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); } /* Render the picture */ $myPicture->stroke(); }
} $Data = right($Data, strlen($Data) - 1); echo '$myData->addPoints(array(' . $Data . '),"Absissa");' . "\r\n"; echo '$myData->setAbscissa("Absissa");' . "\r\n\r\n"; } } if (isset($Axis[0])) { if ($d_axis0_position == "left") { $myData->setAxisPosition(0, AXIS_POSITION_LEFT); } else { $myData->setAxisPosition(0, AXIS_POSITION_RIGHT); } $myData->setAxisName(0, $d_axis0_name); $myData->setAxisUnit(0, $d_axis0_unit); if ($d_axis0_format == "AXIS_FORMAT_METRIC") { $myData->setAxisDisplay(0, 680004); } if ($d_axis0_format == "AXIS_FORMAT_CURRENCY") { $myData->setAxisDisplay(0, 680005, "\$"); } if ($Mode == "Source") { if ($d_axis0_position == "left") { echo '$myData->setAxisPosition(0,AXIS_POSITION_LEFT);' . "\r\n"; } else { echo '$myData->setAxisPosition(0,AXIS_POSITION_RIGHT);' . "\r\n"; } echo '$myData->setAxisName(0,"' . $d_axis0_name . '");' . "\r\n"; echo '$myData->setAxisUnit(0,"' . $d_axis0_unit . '");' . "\r\n\r\n"; } } if (isset($Axis[1])) {
static function makeTimecardBubble($data, $lang = "en") { global $wt; $font = PCHART_FONTS_PATH . "/LiberationSans-Regular.ttf"; if (in_array($wt->uselang, array("zh", "ja", "jp", "ko"))) { $font = PCHART_FONTS_PATH . "/wqy-microhei.ttf"; } if (in_array($wt->uselang, array("he", "bn", "vi", "fa", "ar", "th", "ta", "ka", "hi", "hy", "ml"))) { $font = PCHART_FONTS_PATH . "/unifont.ttf"; } $MyData = new pData(); ksort($data); //get max value $max = 0; foreach ($data as $i => $vals) { if (max($vals) > $max) { $max = max($vals); } } //loop through days of week for ($i = 0; $i <= 6; $i++) { @ksort($data[$i]); $seriesData = array(); $seriesWeight = array(); //Loop through timerange 0=0-3h, 1=4-7h... for ($u = 0; $u <= 5; $u++) { $seriesData[] = $i * 100; $seriesWeight[] = $max ? intval($data[$i][$u] / $max * 100) : 0; } $MyData->addPoints($seriesData, "data" . $i); $MyData->addPoints($seriesWeight, "weight" . $i); } $MyData->addPoints(array("0-4h", "4-8h", "8-12h", "12-16h", "16-20h", "20-24h"), "xtime"); $MyData->setAbscissa("xtime"); $MyData->setAxisDisplay(0, AXIS_FORMAT_CUSTOM, "YAxisFormatDay"); $myPicture = new pImage(900, 280, $MyData, true); $myPicture->setGraphArea(90, 10, 850, 240); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 10, "R" => 34, "G" => 34, "B" => 34)); $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => false); $myPicture->drawScale($scaleSettings); $myBubbleChart = new pBubble($myPicture, $MyData); $bubbleDataSeries = array("data0", "data1", "data2", "data3", "data4", "data5", "data6"); $bubbleWeightSeries = array("weight0", "weight1", "weight2", "weight3", "weight4", "weight5", "weight6"); # $myBubbleChart->bubbleScale( $bubbleDataSeries, $bubbleWeightSeries ); $myBubbleChart->drawBubbleChart($bubbleDataSeries, $bubbleWeightSeries, array("ForceAlpha" => true)); # # $myPicture->setFontProperties(array("FontName"=>PCHART_FONTS_PATH."/arial.ttf","FontSize"=>11,"R"=>34,"G"=>34,"B"=>34)); # $myPicture->drawLegend(900,55,array("Style"=>LEGEND_NOBORDER,"BoxWidth"=>10,"BoxHeight"=>10, "Mode"=>LEGEND_VERTICAL)); ob_start(); imagepng($myPicture->Picture); $imgdata = ob_get_contents(); ob_end_clean(); $rimg = "data:image/png;base64," . base64_encode($imgdata); return $rimg; }
function displayGraph($rrdtool_template, $itemtype, $items_id, $timezone, $time = '1d', $width = '470') { global $DB, $LANG; $timezonefile = str_replace("+", ".", $timezone); // Cache 1 minute if (file_exists(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png")) { $time_generate = filectime(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png"); if ($time_generate + 150 > date('U')) { return; } } $filename = GLPI_PLUGIN_DOC_DIR . "/monitoring/templates/" . $rrdtool_template . "_graph.json"; $loadfile = file_get_contents($filename); if (!$loadfile) { return; } $a_jsong = json_decode($loadfile); // Manage timezones $converttimezone = '0'; if (strstr($timezone, '-')) { $timezone_temp = str_replace("-", "", $timezone); $converttimezone = $timezone_temp * 3600; $timezone = str_replace("-", "+", $timezone); } else { if (strstr($timezone, '+')) { $timezone_temp = str_replace("+", "", $timezone); $converttimezone = $timezone_temp * 3600; $timezone = str_replace("+", "-", $timezone); } } $opts = ""; /* pChart library inclusions */ include_once "../lib/pChart2.1.3/class/pData.class.php"; include_once "../lib/pChart2.1.3/class/pDraw.class.php"; include_once "../lib/pChart2.1.3/class/pImage.class.php"; $MyData = new pData(); // ** Get in table serviceevents $mydatat = array(); $a_labels = array(); $a_ref = array(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmService = new PluginMonitoringService(); $pmService->getFromDB($items_id); $begin = ''; switch ($time) { case '2h': $begin = date('Y-m-d H:i:s', date('U') - 2 * 3600); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `date` > '" . $begin . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = array(); if (isset($this->jsongraph_a_ref[$rrdtool_template])) { $ret = $pmServiceevent->getData($result, $rrdtool_template, array($this->jsongraph_a_ref[$rrdtool_template], $this->jsongraph_a_convert[$rrdtool_template])); } else { $ret = $pmServiceevent->getData($result, $rrdtool_template); } if (is_array($ret)) { $mydatat = $ret[0]; $a_labels = $ret[1]; $a_ref = $ret[2]; if (!isset($this->jsongraph_a_ref[$rrdtool_template])) { $this->jsongraph_a_ref[$rrdtool_template] = $ret[2]; $this->jsongraph_a_convert[$rrdtool_template] = $ret[3]; } } break; case '12h': $begin = date('Y-m-d H:i:s', date('U') - 12 * 3600); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `date` > '" . $begin . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = $pmServiceevent->getData($result, $rrdtool_template); if (is_array($ret)) { $mydatat = $ret[0]; $a_labels = $ret[1]; $a_ref = $ret[2]; } break; case '1d': $begin = date('Y-m-d H:i:s', date('U') - 24 * 3600); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `type`='30m'\n ORDER BY `date`"; $result = $DB->query($query); while ($edata = $DB->fetch_array($result)) { $dat = importArrayFromDB($edata['data']); if (count($dat) > 0) { $datemod = $edata['date']; $split = explode(' ', $datemod); $split2 = explode(':', $split[1]); array_push($a_labels, $split2[0] . ':' . $split2[1]); } foreach ($dat as $name => $value) { if (!isset($mydatat[$name])) { $mydatat[$name] = array(); } array_push($mydatat[$name], $value); } } $ret = $pmServiceevent->getRef($rrdtool_template); $a_ref = $ret[0]; break; case '1w': $begin = date('Y-m-d H:i:s', date('U') - 7 * 24 * 3600); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `type`='6h'\n ORDER BY `date`"; $result = $DB->query($query); while ($edata = $DB->fetch_array($result)) { $dat = importArrayFromDB($edata['data']); if (count($dat) > 0) { $datemod = $edata['date']; $daynum = Calendar::getDayNumberInWeek(PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date'])); $split = explode(' ', $datemod); $split2 = explode(':', $split[1]); array_push($a_labels, $LANG['calendarDay'][$daynum] . " " . $split2[0] . ':' . $split2[1]); } foreach ($dat as $name => $value) { if (!isset($mydatat[$name])) { $mydatat[$name] = array(); } array_push($mydatat[$name], $value); } } $ret = $pmServiceevent->getRef($rrdtool_template); $a_ref = $ret[0]; break; case '1m': $begin = date('Y-m-d H:i:s', date('U') - 30 * 24 * 3600); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `type`='1d'\n ORDER BY `date`"; $result = $DB->query($query); while ($edata = $DB->fetch_array($result)) { $dat = importArrayFromDB($edata['data']); if (count($dat) > 0) { $datemod = $edata['date']; $daynum = Calendar::getDayNumberInWeek(PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date'])); $split = explode(' ', $datemod); $split2 = explode(':', $split[1]); $day = explode("-", $split[0]); array_push($a_labels, $LANG['calendarDay'][$daynum] . " " . $day[2]); } foreach ($dat as $name => $value) { if (!isset($mydatat[$name])) { $mydatat[$name] = array(); } array_push($mydatat[$name], $value); } } $ret = $pmServiceevent->getRef($rrdtool_template); $a_ref = $ret[0]; break; case '0y6m': $begin = date('Y-m-d H:i:s', date('U') - 364 / 2 * 24 * 3600); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `type`='5d'\n ORDER BY `date`"; $result = $DB->query($query); while ($edata = $DB->fetch_array($result)) { $dat = importArrayFromDB($edata['data']); if (count($dat) > 0) { $datemod = $edata['date']; $daynum = date('m', PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date'])); $daynum = $daynum - 1; $split = explode(' ', $datemod); $day = explode("-", $split[0]); array_push($a_labels, $LANG['calendarM'][$daynum] . " " . $day[2]); } foreach ($dat as $name => $value) { if (!isset($mydatat[$name])) { $mydatat[$name] = array(); } array_push($mydatat[$name], $value); } } $ret = $pmServiceevent->getRef($rrdtool_template); $a_ref = $ret[0]; break; case '1y': $begin = date('Y-m-d H:i:s', date('U') - 365 * 24 * 3600); $query = "SELECT * FROM `" . $this->getTable() . "`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `type`='10d'\n ORDER BY `date`"; $result = $DB->query($query); while ($edata = $DB->fetch_array($result)) { $dat = importArrayFromDB($edata['data']); if (count($dat) > 0) { $datemod = $edata['date']; $daynum = date('m', PluginMonitoringServiceevent::convert_datetime_timestamp($edata['date'])); $daynum = $daynum - 1; $split = explode(' ', $datemod); $day = explode("-", $split[0]); array_push($a_labels, $LANG['calendarM'][$daynum] . " " . $day[2]); } foreach ($dat as $name => $value) { if (!isset($mydatat[$name])) { $mydatat[$name] = array(); } array_push($mydatat[$name], $value); } } $ret = $pmServiceevent->getRef($rrdtool_template); $a_ref = $ret[0]; break; } $i = 0; foreach ($mydatat as $name => $data) { $i++; if ($i == '2') { $datat = $data; $data = array(); foreach ($datat as $val) { array_push($data, -$val); } } if (empty($data)) { array_push($data, 0); } $MyData->addPoints($data, $name); $color = str_split($a_ref[$name]); $MyData->setPalette($name, array("R" => hexdec($color[0] . $color[1]), "G" => hexdec($color[2] . $color[3]), "B" => hexdec($color[4] . $color[5]))); } $MyData->setAxisDisplay(0, AXIS_FORMAT_METRIC, 1); // $MyData->setSerieTicks("Probe 2",4); // $MyData->setAxisName(0,"Temperatures"); $MyData->addPoints($a_labels, "Labels"); // $MyData->setSerieDescription("Labels","Months"); $MyData->setAbscissa("Labels"); $myPicture = new pImage(700, 230, $MyData); $myPicture->Antialias = FALSE; $Settings = array("R" => 225, "G" => 204, "B" => 123); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); $Settings = array("R" => 255, "G" => 255, "B" => 255); $myPicture->drawFilledRectangle(60, 40, 650, 200, $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" => "../lib/pChart2.1.3/fonts/verdana.ttf", "FontSize" => 11)); $myPicture->drawText(350, 20, $a_jsong->data[0]->labels[0]->title, array("FontSize" => 13, "Align" => TEXT_ALIGN_MIDDLEMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => "../lib/pChart2.1.3/fonts/verdana.ttf", "FontSize" => 7)); /* Define the chart area */ $myPicture->setGraphArea(60, 40, 650, 200); /* Draw the scale */ $labelskip = round(count($a_labels) / 8); if ($time == '1d') { $labelskip = 3; } else { if ($time == '1m') { $labelskip = 3; } else { if ($time == '0y6m') { $labelskip = 4; } else { if ($time == '1y') { $labelskip = 3; } } } } $scaleSettings = array("XMargin" => 10, "YMargin" => 10, "Floating" => TRUE, "GridR" => 158, "GridG" => 158, "GridB" => 158, "GridAlpha" => 80, "DrawSubTicks" => TRUE, "CycleBackground" => FALSE, "LabelSkip" => $labelskip); $myPicture->drawScale($scaleSettings); /* Write the chart legend */ $myPicture->drawLegend(540, 20, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Turn on Antialiasing */ $myPicture->Antialias = TRUE; $Config = array("ForceTransparency" => 60); /* Draw the area chart */ $myPicture->drawAreaChart($Config); $myPicture->render(GLPI_PLUGIN_DOC_DIR . "/monitoring/" . $itemtype . "-" . $items_id . "-" . $time . $timezonefile . ".png"); return; }
/* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(24, 25, 26, 25, 25), "My Serie 1"); $MyData->addPoints(array(12, 13, 14, 16, 18), "My Serie 2"); $MyData->addPoints(array(80, 76, 73, 71, 33), "My Serie 3"); $MyData->addPoints(array(47, 67, 78, 76, 54), "My Serie 4"); /* Define the series name */ $MyData->setSerieDescription("My Serie 1", "Temperature"); $MyData->setSerieDescription("My Serie 2", "Humidity"); /* Dispatche the series on different axis */ $MyData->setSerieOnAxis("My Serie 1", 1); $MyData->setSerieOnAxis("My Serie 2", 1); $MyData->setSerieOnAxis("My Serie 3", 2); $MyData->setSerieOnAxis("My Serie 4", 2); /* Set the format of the axis */ $MyData->setAxisDisplay(1, AXIS_FORMAT_DEFAULT); $MyData->setAxisDisplay(2, AXIS_FORMAT_DEFAULT); $MyData->setAxisDisplay(1, AXIS_FORMAT_TIME, "H:i"); /* Set the unit of the axis */ $MyData->setAxisUnit(1, "°C"); $MyData->setAxisUnit(2, "%"); /* Set the name of the axis */ $MyData->setAxisName(1, "Temperature"); $MyData->setAxisName(2, "Humidity"); /* Change the color of one serie */ $serieSettings = array("R" => 229, "G" => 11, "B" => 11, "Alpha" => 80); $MyData->setPalette("My Serie 4", $serieSettings); /* Load a palette file */ $MyData->loadPalette("resources/palette.txt", FALSE); /* Output the data structure */ print_r($MyData->getData());