/** * * @param array $data * @param string $title * @return \App_Util_Chart */ public static function pieChart(array $data, $title) { $fontsChart = APPLICATION_PATH . '/../library/pChart/fonts/verdana.ttf'; App_Util_Chart::loadClass(array('pData', 'pDraw', 'pPie', 'pImage')); $dataGraph = new pData(); $dataGraph->addPoints($data['series'], 'Series'); $dataGraph->addPoints($data['labels'], 'Labels'); $dataGraph->setAbscissa('Labels'); $myPicture = new pImage(700, 300, $dataGraph, TRUE); $settings = array('R' => 250, 'G' => 250, 'B' => 250); $myPicture->drawFilledRectangle(0, 0, 700, 300, $settings); $myPicture->drawRectangle(0, 0, 699, 299, array('R' => 0, 'G' => 0, 'B' => 0)); $myPicture->setFontProperties(array('FontName' => $fontsChart, 'FontSize' => 10, 'R' => 0, 'G' => 0, 'B' => 0)); $pieChart = new pPie($myPicture, $dataGraph); $pieChart->draw3DPie(350, 180, array('ValuePadding' => 30, 'WriteValues' => TRUE, 'ValuePosition' => PIE_VALUE_OUTSIDE, 'Border' => TRUE, 'ValueR' => 0, 'ValueG' => 0, 'ValueB' => 0, 'Radius' => 130)); $pos = floor(strlen($title) / 2); $start = 350 - $pos * 9; $myPicture->setFontProperties(array('FontName' => $fontsChart, 'FontSize' => 14)); $myPicture->drawText($start, 25, $title, array('R' => 0, 'G' => 0, 'B' => 0)); $myPicture->setFontProperties(array('FontName' => $fontsChart, 'FontSize' => 10, 'R' => 0, 'G' => 0, 'B' => 0)); $pieChart->drawPieLegend(500, 50, array('Style' => LEGEND_NOBORDER)); ob_start(); imagepng($myPicture->Picture); $image = ob_get_clean(); return $image; }
/** * Creates a Chart Image with the count(Year(fecha_nacimiento)) * * @param DomDocument $qResult The query result * * @return string with the binary stream of a png picture. * @see listadoPersonasXedad() */ public static function listadoPersonasXedadCreateChart(DomDocument $qResult) { // Todo: add chart to /result/chart $xPath = new DOMXPath($qResult); $countedNodes = $xPath->query('/result/Persona_Collection/Persona/counted/text()'); $count = array(); foreach ($countedNodes as $node) { $count[] = $node->nodeValue; } $fechaNodes = $xPath->query('/result/Persona_Collection/Persona/years/text()'); $years = array(); foreach ($fechaNodes as $node) { $years[] = $node->nodeValue; } /* Create and populate the pData object */ $myData = new pData(); $myData->addPoints($count, "Years"); $myData->setSerieDescription("Years", "Año de Nacimiento de las personas"); /* Define the absissa serie */ $myData->addPoints($years, "Labels"); $myData->setAbscissa("Labels"); $myPicture = self::listadoPersonasXedadConfigChart($myData); /* Create the pPie object */ $pieChart = new pPie($myPicture, $myData); /* Draw AA pie chart */ $pieChart->draw2DPie(200, 100, array("Border" => TRUE)); /* Write a legend box under the 1st chart */ $pieChart->drawPieLegend(90, 176, array("Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $fname = PathsUtils::createChartFileName(); $myPicture->render($fname); $picFile = file_get_contents($fname); return $picFile; }
function index() { /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(getGenders($this->db), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("Female", "Male"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(240, 180, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => pClass . "fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw a splitted pie chart */ $PieChart->draw3DPie(120, 90, array("Radius" => 100, "DataGapAngle" => 12, "DataGapRadius" => 10, "Border" => TRUE)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => pClass . "fonts/Silkscreen.ttf", "FontSize" => 6, "R" => 0, "G" => 0, "B" => 0)); $PieChart->drawPieLegend(140, 160, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->stroke(); //$myPicture->autoOutput("pictures/example.draw3DPie.transparent.png"); }
/** *Forum Functions */ function block_mystats_forum_chart($allTopics = 0, $allReplies = 0, $allTopicsString, $allRepliesString, $userid) { $MyForumData = new pData(); $MyForumData->addPoints(array($allReplies, $allTopics), "Value"); $MyForumData->addPoints(array($allRepliesString . ': ' . $allReplies, $allTopicsString . ': ' . $allTopics), "Legend"); $MyForumData->setAbscissa("Legend"); $myForumPicture = new pImage(350, 150, $MyForumData); $forumPieChart = new pPie($myForumPicture, $MyForumData); $myForumPicture->setShadow(FALSE); $myForumPicture->setFontProperties(array("FontName" => "../blocks/mystats/pChart2.1.3/fonts/Forgotte.ttf", "FontSize" => 13, "R" => 80, "G" => 80, "B" => 80)); $forumPieChart->draw3DPie(175, 100, array("Radius" => 80, "DrawLabels" => TRUE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE)); $imgName = sha1($userid . 'forum') . '.png'; $myForumPicture->Render('../blocks/mystats/img/' . $imgName); return '<img src="../blocks/mystats/img/' . $imgName . '" alt="' . $allTopicsString . ': ' . $allTopics . ', ' . $allRepliesString . ': ' . $allReplies . '">'; }
function DrawPieChart($pChart, $pChartPicture, $x, $y, $name, $values, $labels) { $pChart->removeSerie("Serie"); $pChart->removeSerie("Labels"); $pChart->addPoints($values, "Serie"); $pChart->setSerieDescription("Serie", ""); $pChart->addPoints($labels, "Labels"); $pChart->setAbscissa("Labels"); $text = array("Align" => TEXT_ALIGN_BOTTOMMIDDLE, "FontName" => "pChart/fonts/arial.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80); $pChartPicture->setFontProperties($text); $pChartPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); $PieChart = new pPie($pChartPicture, $pChart); $PieChart->draw2DPie($x, $y, array("Radius" => 150, "ValuePosition" => PIE_VALUE_INSIDE, "WriteValues" => PIE_VALUE_PERCENTAGE, "ValueR" => 80, "ValueG" => 80, "ValueB" => 80, "LabelStacked" => TRUE, "DrawLabels" => TRUE, "Border" => TRUE)); $pChartPicture->setShadow(FALSE); $nameText = array("Align" => TEXT_ALIGN_BOTTOMMIDDLE, "FontName" => "pChart/fonts/arialbd.ttf", "FontSize" => 11, "R" => 80, "G" => 80, "B" => 80); $pChartPicture->drawText($x, $y - 200, ucfirst($name), $nameText); $PieChart->drawPieLegend($x + 250, $y - 150, array("Alpha" => 20, "BoxSize" => 10)); }
function RenderQualityQuota(&$debug1) { $parameters = [[10, 8, 6, 4, 2]]; coinQualityCount($parameters[0], $array_result); $MyData = new pData(); $MyData->addPoints($array_result, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($parameters[0], "Labels"); $MyData->setAbscissa("Labels"); /* Create the cache object */ $myCache = new pCache(array("CacheFolder" => PCHART_PATH . "/class/cache")); /* Compute the hash linked to the chart data */ $ChartHash = $myCache->getHash($MyData); /* Test if we got this hash in our cache already */ if ($myCache->isInCache($ChartHash)) { /* If we have it, get the picture from the cache! */ $myCache->saveFromCache($ChartHash, WWW_PATH . "/tmp/qualityquota.png"); $debug1 = "Old image"; } else { /* Create the pChart object */ $myPicture = new pImage(470, 310, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => PCHART_PATH . "/fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw a splitted pie chart */ $myPicture->setFontProperties(array("FontName" => PCHART_PATH . "/fonts/GeosansLight.ttf", "FontSize" => 12, "R" => 0, "G" => 0, "B" => 0)); $PieChart->draw2DPie(210, 130, array("Radius" => 100, "DataGapAngle" => 0, "DataGapRadius" => 10, "DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE, "WriteValues" => TRUE, "ValuePosition" => PIE_VALUE_INSIDE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValuePadding" => -20, "SecondPass" => TRUE)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => PCHART_PATH . "/fonts/GeosansLight.ttf", "FontSize" => 12, "R" => 0, "G" => 0, "B" => 0)); $PieChart->drawPieLegend(10, 300, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Push the rendered picture to the cache */ $myCache->writeToCache($ChartHash, $myPicture); /* Render the picture */ $myPicture->Render(WWW_PATH . "/tmp/qualityquota.png"); $debug1 = "Picture rendered"; } }
function ring2d($x, $y, $name) { $MyData = new pData(); $MyData->addPoints($x, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($y, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(500, 250, $MyData); /* Draw a solid background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 500, 500, $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, 500, 500, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 500, 30, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 500, 250, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "mod/pchart/fonts/verdana.ttf", "FontSize" => 12)); $myPicture->drawText(15, 20, $name, array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "mod/pchart/fonts/verdana.ttf", "FontSize" => 12, "R" => 80, "G" => 80, "B" => 80)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ $PieChart->draw2DRing(390, 140, array("WriteValues" => TRUE, "ValueR" => 255, "ValueG" => 255, "ValueB" => 255, "Border" => TRUE)); /* Write the legend box */ $myPicture->setShadow(FALSE); $PieChart->drawPieLegend(10, 50, array("Alpha" => 20)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("2dring.png"); }
function renderChart($chartType, $title, $prepData, $legend) { $width = 800; $height = 500; $titleHeight = 20; /* * Create a dataset we can use */ $dataSet = array_values($prepData); $imgData = new pData(); if ($chartType == "bar") { $imgData->addPoints($dataSet, "data"); $imgData->addPoints($legend, "legend"); $imgData->setAbscissa("legend"); $imgData->setPalette("data", array("R" => 0, "G" => 108, "B" => 171, "Alpha" => 100)); $img = new pImage($width, $height, $imgData); $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100)); $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10)); $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255)); $img->setFontProperties(array("R" => 255, "G" => 255, "B" => 255, "FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9)); $img->setGraphArea(60, $titleHeight + 20, $width - 50, $height - 30); $img->drawScale(array("GridR" => 200, "GridG" => 200, "GridB" => 200, "Mode" => SCALE_MODE_START0)); $img->drawBarChart(array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "Surrounding" => 10)); } elseif ($chartType == "3Dpie") { $imgData->addPoints($dataSet, "data"); $imgData->addPoints($legend, "legend"); $imgData->setAbscissa("legend"); $img = new pImage($width, $height, $imgData, TRUE); $PieChart = new pPie($img, $imgData); $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100)); $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10)); $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255)); $PieChart->setSliceColor(0, array("R" => 0, "G" => 108, "B" => 171)); $PieChart->setSliceColor(1, array("R" => 205, "G" => 159, "B" => 0)); $PieChart->setSliceColor(2, array("R" => 0, "G" => 171, "B" => 0)); $PieChart->setSliceColor(3, array("R" => 171, "G" => 28, "B" => 0)); $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9)); $PieChart->draw3DPie($width / 2, $height / 2 + $titleHeight, array("Radius" => $width / 2 - 100, "SecondPass" => TRUE, "DrawLabels" => TRUE, "WriteValues" => TRUE, "Precision" => 2, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 100, "SkewFactor" => 0.6, "LabelR" => 255, "LabelG" => 255, "LabelB" => 255, "LabelAlpha" => 100)); } # if if (isset($img)) { ob_start(); $img->render(NULL); $imageString = ob_get_clean(); $dimensions = $this->_svcImageUtil->getImageDimensions($imageString); return array('metadata' => $dimensions, 'content' => $imageString); } else { return false; } # else }
function generate_graph_image($outputfile) { // Create Graph Dataset and set axis attributes $graphData = new pData(); $graphData->setAxisName(0, $this->ytitle_actual); $graphData->addPoints($this->xlabels, "xaxis"); $graphData->setSerieDescription("xaxis", "xaxis"); $graphData->setAbscissa("xaxis"); $graphData->setXAxisName("ooo"); // Add each series of plot values to dataset, but Reportico will // duplicate series were the same data are displayed in different forms // so only add each unique series once $seriesadded = array(); foreach ($this->plot as $k => $v) { $series = $v["name"] . $k; $graphData->addPoints($v["data"], $series); $graphData->setSerieDescription($series, $v["legend"]); } /* $graph->xgrid->SetColor($this->xgridcolor); $graph->ygrid->SetColor($this->ygridcolor); */ /* switch ( $this->xgriddisplay ) { case "all": $graph->xgrid->Show(true,true); break; case "major": $graph->xgrid->Show(true,false); break; case "minor": $graph->xgrid->Show(false,true); break; case "none": default: $graph->xgrid->Show(false,false); break; } switch ( $this->ygriddisplay ) { case "all": $graph->ygrid->Show(true,true); break; case "major": $graph->ygrid->Show(true,false); break; case "minor": $graph->ygrid->Show(false,true); break; case "none": default: $graph->ygrid->Show(false,false); break; } */ /* $graph->xaxis->SetFont($fontfamilies[$xaxisfont],$fontstyles[$xaxisfontstyle], $xaxisfontsize); $graph->xaxis->SetColor($xaxiscolor,$xaxisfontcolor); $graph->yaxis->SetFont($fontfamilies[$yaxisfont],$fontstyles[$yaxisfontstyle], $yaxisfontsize); $graph->yaxis->SetColor($yaxiscolor,$yaxisfontcolor); $graph->xaxis->title->SetFont($fontfamilies[$xtitlefont],$fontstyles[$xtitlefontstyle], $xtitlefontsize); $graph->xaxis->title->SetColor($xtitlecolor); $graph->yaxis->title->SetFont($fontfamilies[$ytitlefont],$fontstyles[$ytitlefontstyle], $ytitlefontsize); $graph->yaxis->title->SetColor($ytitlecolor); $graph->xaxis->SetLabelAngle(90); $graph->xaxis->SetLabelMargin(15); $graph->yaxis->SetLabelMargin(15); $graph->xaxis->SetTickLabels($xlabels); $graph->xaxis->SetTextLabelInterval($xticklabint); $graph->yaxis->SetTextLabelInterval($yticklabint); $graph->xaxis->SetTextTickInterval($xtickinterval); $graph->yaxis->SetTextTickInterval($ytickinterval); */ /* if ( $gridpos == "front" ) $graph->SetGridDepth(DEPTH_FRONT); */ // Display the graph /*?$graph->Stroke();*/ $this->apply_defaults_internal(); //echo "oo<BR>"; //echo "<PRE>"; //var_dump($graphData); //echo $this->width."<BR>"; //echo $this->height_actual."<BR>"; $graphImage = new pImage($this->width_actual, $this->height_actual, $graphData); /* Turn of Antialiasing */ $graphImage->Antialias = TRUE; // Add gradient fill from chosen background color to white $startgradient = $this->htmltorgb("#ffffff"); $color = $this->htmltorgb($this->graphcolor); $graphImage->drawGradientArea(0, 0, $this->width_actual, $this->height_actual, DIRECTION_VERTICAL, array("StartR" => $startgradient[0], "StartG" => $startgradient[1], "StartB" => $startgradient[2], "EndR" => $color[0], "EndG" => $color[1], "EndB" => $color[2], "Alpha" => 100)); /* Add a border to the picture */ $graphImage->drawRectangle(0, 0, $this->width_actual - 1, $this->height_actual - 1, array("R" => 200, "G" => 200, "B" => 200)); /* Set the title font and draw it */ $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->titlefont, "FontSize" => $this->titlefontsize)); $this->titlecolor = $this->htmltorgb($this->titlecolor); $graphImage->drawText(20, 30, $this->title_actual, array("R" => $this->titlecolor[0], "G" => $this->titlecolor[1], "B" => $this->titlecolor[2])); /* Set the default font from the X title font */ $graphImage->setFontProperties(array("FontName" => PCHARTFONTS_DIR . $this->xtitlefont, "FontSize" => $this->xtitlefontsize)); /* Define the chart area */ $graphImage->setGraphArea($this->marginleft, $this->margintop, $this->width_actual - $this->marginright, $this->height_actual - $this->marginbottom); //$scaleSettings = array("GridR"=>200,"GridG"=>200,"GridB"=>200,"DrawSubTicks"=>TRUE,"CycleBackground"=>TRUE,"LabelRotation"=>30); //$graphImage->drawScale($scaleSettings); //$settings = array("Surrounding"=>-30,"InnerSurrounding"=>30); //$graphImage->drawBarChart($settings); //$graphImage->autoOutput("pictures/example.drawBarChart.simple.png"); //return; // Before plotting a series ensure they are all not drawable. /// Plot the chart data $stackeddrawn = false; $stackedexists = false; $barexists = false; foreach ($this->plot as $k => $v) { if ($v["type"] == "STACKEDBAR") { $stackedexists = true; } if ($v["type"] == "STACKEDBAR" || $v["type"] == "BAR") { $barexists = true; } } /* Draw the scale */ $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "LabelRotation" => 30); // For stacked charts fix up the Max and Min values; if ($stackedexists) { $scaleMin = "Unknown"; $scaleMax = 0; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; $min = $graphData->getMin($series); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $scaleMax = $scaleMax + $graphData->getMax($series); } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); $scaleSettings["Mode"] = SCALE_MODE_MANUAL; $scaleSettings["ManualScale"] = $AxisBoundaries; } else { if ($barexists) { $scaleMin = "Unknown"; $scaleMax = 0; foreach ($this->plot as $k => $v) { if ($v["type"] == "BAR" || $v["type"] == "STACKEDBAR") { $series = $v["name"] . $k; $min = $graphData->getMin($series); if ($scaleMin == "Unknown" || $min < $scaleMin) { $scaleMin = $min; } $max = $graphData->getMax($series); if ($scaleMax == "Unknown" || $max > $scaleMax) { $scaleMax = $max; } } } if ($scaleMin > 0) { $scaleMin = 0; } $range = $scaleMax - $scaleMin; // Make scales based on 5% of the range of values $scaleMax = round($range * 0.05 + $scaleMax); if ($scaleMin < 0) { $scaleMin = $scaleMin - round($range * 0.05); } $AxisBoundaries = array(0 => array("Min" => $scaleMin, "Max" => $scaleMax)); $scaleSettings["Mode"] = SCALE_MODE_MANUAL; $scaleSettings["ManualScale"] = $AxisBoundaries; } } $graphImage->drawScale($scaleSettings); // If there's a Pie chart we want to draw different legends $piechart = false; foreach ($this->plot as $k => $v) { foreach ($this->plot as $k1 => $v1) { $series = $v1["name"] . $k1; $graphData->setSerieDrawable($series, FALSE); } $series = $v["name"] . $k; $graphData->setSerieDrawable($series, TRUE); switch ($v["type"]) { case "PIE": $piechart = true; $pie = new pPie($graphImage, $graphData); //$pie->draw2DPie($width_actual / 2,$height_actual / 2,80,array("DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE)); $pie->draw2DPie($width_actual / 2, $height_actual / 2, 80, array("WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255)); break; case "PIE3D": $piechart = true; $pie = new pPie($graphImage, $graphData); $pie->draw3DPie($this->width_actual / 2, $this->height_actual / 2, 80, array("SecondPass" => FALSE)); break; case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists) { foreach ($this->plot as $k1 => $v1) { if ($v1["type"] == "BAR" || $v1["type"] == "STACKEDBAR") { $graphData->setSerieDrawable($v1["name"] . $k1, TRUE); } } } $stackeddrawn = true; $settings = array("Surrounding" => -30, "InnerSurrounding" => 30); if ($stackedexists) { $graphImage->drawStackedBarChart($settings); } else { $graphImage->drawBarChart($settings); } break; case "LINE": default: if (count($v["data"]) == 1) { $v["data"][] = 0; } $graphImage->drawLineChart($settings); break; } } $graphData->drawAll(); if ($piechart) { $pie->drawPieLegend($this->width_actual - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } else { $graphImage->drawLegend($this->width_actual - 180, 22, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } $graphImage->setShadow(TRUE, array("X" => 0, "Y" => 0, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); $graphImage->render($outputfile); return true; }
function func_piegraphGenerate($student_id, $time, $name, $basepath) { $metricResult = $this->func_getTimeTakenResult($student_id); $book_name = array(); $book_time = array(); if (empty($metricResult)) { $book_name[] = ""; $book_time[] = ""; } foreach ($metricResult as $matric) { $book_name[] = $matric['book_name']; $book_time[] = $matric['book_wise_sum']; } $total_time = array_sum($book_time); $MyData = new pData(); $MyData->addPoints($book_time, "ScoreA"); /* Define the absissa serie */ $MyData->addPoints($book_name, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(500, 317, $MyData, TRUE); /* Draw a solid background */ $Settings = array("R" => 255, "G" => 255, "B" => 255, "Dash" => 0, "DashR" => 193, "DashG" => 172, "DashB" => 237); $myPicture->drawFilledRectangle(0, 0, 400, 230, $Settings); /* Draw a gradient overlay */ $Settings = array("StartR" => 255, "StartG" => 255, "StartB" => 255, "EndR" => 255, "EndG" => 255, "EndB" => 255, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 400, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 0, 0, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => $basepath . "verdana.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Define the slice color */ $PieChart->setSliceColor(0, array("R" => 40, "G" => 74, "B" => 134)); $PieChart->setSliceColor(1, array("R" => 97, "G" => 77, "B" => 63)); $PieChart->setSliceColor(2, array("R" => 97, "G" => 113, "B" => 63)); /* Draw a simple pie chart */ /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw a splitted pie chart */ $PieChart->draw3DPie(230, 175, array("WriteValues" => TRUE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "DrawLabels" => TRUE)); /* Render the picture (choose the best way) */ $picname = $student_id . '_' . $name . '_' . $time . '.png'; $this->fun_getImageLog($student_id, $picname, $name, $time, 'pie'); $myPicture->render("uploads/graph/" . $picname); $book_time = array('book_time' => $book_time); return array_merge((array) $book_name, $book_time); // return $book_name.'-'.$book_time; }
function PlotPie($rowA, $rowB, $name, $cch) { include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pData.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pDraw.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pImage.class.php"; include $_SERVER['DOCUMENT_ROOT'] . "/TBSIM/Lib/class/pPie.class.php"; $MyData = new pData(); $MyData->addPoints($rowA, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($rowB, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(700, 630, $MyData); $myPicture->setFontProperties(array("FontName" => "fonts/Forgotte.ttf", "FontSize" => 14)); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 252, "G" => 252, "B" => 252, "DrawBox" => 1, "BoxAlpha" => 30); //$myPicture->drawText(350,25,$name,$TextSettings); $myPicture->setShadow(FALSE); $myPicture->setGraphArea(50, 50, 675, 690); //$myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"fonts/pf_arma_five.ttf","FontSize"=>6)); $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" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL); //$myPicture->drawScale($Settings); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ if ($cch == 11) { $PieChart->draw2DPie(160, 140, array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); } if ($cch == 12) { $PieChart->draw2DRing(160, 140, array("WriteValues" => TRUE, "ValueR" => 255, "ValueG" => 255, "ValueB" => 255, "Border" => TRUE)); } if ($cch == 13) { $PieChart->draw3DPie(160, 140, array("Radius" => 70, "DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); } /* Write the legend box */ $myPicture->setShadow(FALSE); $PieChart->drawPieLegend(15, 40, array("Alpha" => 20)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.draw2DPie.labels.png"); }
function buildChartImagePie($chartPicture, $chartData, $reportData, $imageHeight, $imageWidth, $xName, $recordImageMap) { $PieChart = new pPie($chartPicture, $chartData); $x = 0; foreach ($reportData as $row) { $PieChart->setSliceColor($x, $this->getColour($row[$xName], true)); $x++; } $PieChart->draw2DPie($imageWidth / 3, $imageHeight / 2, array("Border" => TRUE, 'Radius' => 200, '' => true, "RecordImageMap" => $recordImageMap)); $PieChart->drawPieLegend($imageWidth * 0.7, $imageHeight / 3, array('FontSize' => 10, "FontName" => "modules/AOR_Charts/lib/pChart/fonts/verdana.ttf", 'BoxSize' => 14)); }
$LegendMode = "LEGEND_HORIZONTAL"; } /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($Score, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($Labels, "Labels"); $MyData->setAbscissa("Labels"); $MyData->loadPalette('../palettes/MADmin.color', TRUE); /* Create the pChart object */ $myPicture = new pImage($ImageSize[0], $ImageSize[1], $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../fonts/" . $Font . ".ttf", "FontSize" => $FontSize, "R" => $FontR, "G" => $FontG, "B" => $FontB)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw a splitted pie chart */ $PieChart->draw3DPie($ChartSize[0], $ChartSize[1], array("Radius" => $Radius, "DataGapAngle" => $DataGapAngle, "DataGapRadius" => $DataGapRadius, "Border" => TRUE)); /* Write the legend box */ if ($ShowLabels != 0) { $myPicture->setFontProperties(array("FontName" => "../fonts/" . $LegendFont . ".ttf", "FontSize" => $LegendFontSize, "R" => $LegendFontR, "G" => $LegendFontG, "B" => $LegendFontB)); //$PieChart->drawPieLegend(140,160,array("Style"=>$LegendStyle,"Mode"=>$LegendMode)); $PieChart->drawPieLegend($LegendSize[0], $LegendSize[1], array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } /* $TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE, "R"=>0, "G"=>0, "B"=>0); $myPicture->drawText(10,10,"My first pChart project",$TextSettings); $myPicture->drawText(10,30,"My first pChart project",$TextSettings); */
<?php /* CAT:Pie charts */ /* pChart library inclusions */ include "../../../etc/lib/pChart2/class/pData.class.php"; include "../../../etc/lib/pChart2/class/pDraw.class.php"; include "../../../etc/lib/pChart2/class/pPie.class.php"; include "../../../etc/lib/pChart2/class/pImage.class.php"; $a = $_GET['used']; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(56756756, 49999996), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("Free Space", "Used Space"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(350, 250, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../../../etc/lib/pChart2/fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw a splitted pie chart */ $PieChart->draw3DPie(150, 120, array("Radius" => 150, "DataGapAngle" => 5, "DataGapRadius" => 7, "Border" => TRUE)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../../../etc/lib/pChart2/GeosansLight.ttf", "FontSize" => 8, "R" => 0, "G" => 0, "B" => 0)); $PieChart->drawPieLegend(140, 240, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.draw3DPie.transparent.png");
$myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Draw a gradient overlay */ $Settings = array("StartR" => 209, "StartG" => 150, "StartB" => 231, "EndR" => 111, "EndG" => 3, "EndB" => 138, "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" => 100)); /* 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, "pPie - Draw 2D pie charts", array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw a simple pie chart */ $PieChart->draw2DPie(120, 125, array("SecondPass" => FALSE)); /* Draw an AA pie chart */ $PieChart->draw2DPie(340, 125, array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); /* Draw a splitted pie chart */ $PieChart->draw2DPie(560, 125, array("WriteValues" => PIE_VALUE_PERCENTAGE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255)); /* Write the legend */ $myPicture->setFontProperties(array("FontName" => "../fonts/pf_arma_five.ttf", "FontSize" => 6)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20)); $myPicture->drawText(120, 200, "Single AA pass", array("DrawBox" => TRUE, "BoxRounded" => TRUE, "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE)); $myPicture->drawText(440, 200, "Extended AA pass / Splitted", array("DrawBox" => TRUE, "BoxRounded" => TRUE, "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6, "R" => 255, "G" => 255, "B" => 255)); $PieChart->drawPieLegend(380, 8, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */
if ($idx == 0) { $pieValueKeyLabel = $field; $pieValueKey = $arrCols[$field][$rowPie]; } else { if (!isset($chart_cols) or in_array($idx, $chart_cols)) { $arrPieLabels[] = $field; $arrPieValues[] = $arrCols[$field][$rowPie]; } } } $myData->addPoints($arrPieLabels, 'pieLabel'); $myData->addPoints($arrPieValues, $pieValueKey); $abscissa = 'pieLabel'; $myData->setAbscissa($abscissa); /* Create the pPie object */ $PieChart = new pPie($myPicture, $myData); $myPicture->setFontProperties(array("FontName" => "./fonts/msyh.ttf", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0)); /* Define the slice color */ // 若设置了色板,配入饼图 if (isset($palette)) { for ($slice = 0; $slice < count($arrPieLabels); $slice++) { $PieChart->setSliceColor($slice, $palette['serie'][$slice % $palette['serie_num']]); } } /* Draw Pie */ // 设置数值显示类型,1:显示数值,2:显示比例,否则不显示; $WriteValues = NULL; if ($pieValue == 1) { $WriteValues = PIE_VALUE_NATURAL; } if ($pieValue == 2) {
private function drawPieChart($filename, $dataSeries, $labelSeries) { $dataSeries = array_values($dataSeries); /* Create and populate the pData object */ $data = new pData(); $data->addPoints($dataSeries); /* Calculate percentage and add to the labels */ $total = array_sum($dataSeries); for ($i = 0; $i < count($dataSeries); $i++) { $labelSeries[$i] .= " (" . ceil($dataSeries[$i] / $total * 100) . "%)"; } /* Define the absissa serie */ $data->addPoints($labelSeries, "Labels"); $data->setAbscissa("Labels"); /* Create the pChart object */ $picture = new pImage(400, 250, $data, true); /* Set the default font properties */ $picture->setFontProperties(array("FontName" => "../lib/pchart-2.1.3/fonts/verdana.ttf", "FontSize" => 8)); /* Enable shadow computing */ $picture->setShadow(true, array("X" => 2, "Y" => 2, "R" => 150, "G" => 150, "B" => 150, "Alpha" => 100)); /* Create the pPie object */ $pieChart = new pPie($picture, $data); /* Draw a simple pie chart */ $pieChart->draw2DPie(115, 125, array("Radius" => 110, "SecondPass" => true)); $pieChart->drawPieLegend(250, 10); $picture->render($filename . '.png'); }
protected function plotPieChart(pImage $picture, pData $data, $options = array()) { $pie = new pPie($picture, $data); $raw_data = $data->getData(); $n_series = $options['n_series']; $series_names = array_keys($raw_data['Series']); $chart_height = $options['chart_height']; $title_height = isset($options['title_height']) ? $options['title_height'] : 50; $c = -1; foreach ($series_names as $key => $id) { if ('labels' == $id) { continue; } $c++; $data->setSerieDrawable($id, true); $posX = $c == 0 ? 225 : (($c + 1) % 2 == 1 ? 225 + 450 : 225); $posY = $c == 0 ? $chart_height / 2 : $chart_height / 2 + $chart_height * (floor($c / 2) + $c % 2); $posY = $title_height + $posY; // title $options = array('Radius' => $chart_height / 2 * 0.9, 'SkewFactore' => 0.5, 'SliceHeight' => 10, 'DataGapAngle' => 0, 'Border' => TRUE, 'BorderR' => 255, 'BorderG' => 255, 'BorderB' => 255, 'SecondPass' => true, 'WriteValues' => true, 'ValueR' => 0, 'ValueG' => 0, 'ValueB' => 0); $pie->draw3DPie($posX, $posY, $options); $data->setSerieDrawable($id, false); $TextSettings = array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 40, "G" => 40, "B" => 43); $picture->drawText($posX, $posY - $chart_height / 2 * 0.9, $raw_data['Series'][$id]['Description'], $TextSettings); } $Config = array("FontName" => sfConfig::get('sf_web_dir') . "/fonts/Ubuntu-R.ttf", "FontSize" => 6, "FontR" => 40, "FontG" => 40, "FontB" => 43, "Margin" => 6, "Alpha" => 100, "BoxSize" => 5, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL, "Family" => LEGEND_FAMILY_LINE); $pie->drawPieLegend(450, 50, $Config); }
/** * Desenha um gráfico de torta * @param $title título do graico * @param $data vetor contendo os dados do gráfico * @param $width largura do gráfico * @param $height altura do gráfico * @param $outputPath caminho de saída do gráfico */ public function drawPieChart($title, $data, $width, $height, $outputPath) { // cria o modelo de dados $modelo = new pData(); $newdata = array(); foreach ($data as $legend => $value) { $newdata[] = $value == NULL ? VOID : $value; $labels[] = $legend; } $modelo->addPoints($newdata, "ScoreA"); /* Define the absissa serie */ $modelo->addPoints($labels, "Labels"); $modelo->setAbscissa("Labels"); // cria o objeto que irá conter a imagem do gráfico $imagem = new pImage($width, $height, $modelo); // adiciona uma borda na forma de um retângulo dentro da imagem $imagem->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0)); // escreve um título dentro do gráfico $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/Forgotte.ttf", "FontSize" => 11)); $imagem->drawText(60, 35, $title, array("FontSize" => 20, "Align" => TEXT_ALIGN_BOTTOMLEFT)); // define a fonte dos dados do gráfico $imagem->setFontProperties(array("FontName" => "app/lib/pchart/fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); // cria o gráfico de torta $pie = new pPie($imagem, $modelo); // desenha o gráfico de torta $pie->draw3DPie($width / 2, $height / 2, array('WriteValues' => TRUE, 'DrawLabels' => TRUE, "Radius" => $width / 4, 'ValueR' => 0, 'ValueG' => 0, 'ValueB' => 0, 'ValueAlpha' => 80)); // desenha a legenda do gráfico $imagem->setShadow(FALSE); $pie->drawPieLegend(15, 40, array("Alpha" => 20)); // grava o gráfico em um arquivo $imagem->render($outputPath); }
$MyData->addPoints(array(40, 60, 15, 10, 6, 4), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("<10", "10<>20", "20<>40", "40<>60", "60<>80", ">80"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(300, 260, $MyData); /* Retrieve the image map */ if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"])) { $myPicture->dumpImageMap("ImageMap3DPieChart", IMAGE_MAP_STORAGE_FILE, "3DPieChart", "../tmp"); } /* Set the image map name */ $myPicture->initialiseImageMap("ImageMap3DPieChart", IMAGE_MAP_STORAGE_FILE, "3DPieChart", "../tmp"); /* Draw a solid background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 300, 300, $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, 300, 260, DIRECTION_VERTICAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 299, 259, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => FONT_PATH . "/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $Settings = array("RecordImageMap" => TRUE); $PieChart = new pPie($myPicture, $MyData, $Settings); /* Draw an AA pie chart */ $PieSettings = array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE, "RecordImageMap" => TRUE); $PieChart->draw3DPie(160, 150, $PieSettings); /* Render the picture (choose the best way) */ $myPicture->autoOutput("../tmp/3DPieChart.png");
/** * eval_ccpc_genGraphPie - Génère un graphique de type camenbert sous forme d'image au format PNG * * @category : eval_ccpc_functions * @param array $data Données à partir desquelles le graphique est généré * @return string URL de l'image générée * * @Author Ali Bellamine * * Structure de $data :<br> * ['data'][nom du label] => (int) Valeur liée au label<br> * ['settings']['height'] => (int) Hauteur du graphique (en px)<br> * ['settings']['width'] => (int) Largeur du graphique (en px) * */ function eval_ccpc_genGraphPie($data) { // On vérifie les données fournit if (isset($data) && isset($data['data']) && count($data['data']) > 0) { // On récupère le hash de $data $hash = md5(json_encode($data)); // Chemin du fichier $filePath = PLUGIN_PATH . 'cache/' . $hash . '.png'; $filePathURI = ROOT . 'evaluations/ccpc/cache/' . $hash . '.png'; // Si le hash existe déjà : on renvoie le lien de l'image // sinon en crée le graphique if (is_file($filePath)) { return $filePathURI; } else { // On crée l'image /* On inclut la librairie */ require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pData.class.php'; require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pPie.class.php'; require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pDraw.class.php'; require_once PLUGIN_PATH . 'core/pChart2.1.4/class/pImage.class.php'; /* On crée l'objet pData */ // Préparation des données $tempDataArray = array(); // Contient les données chiffrés de chaque part du camenbert $tempLegendArray = array(); // Contient la légend chaque part de camenbert foreach ($data['data'] as $tempDataLegend => $tempDataValue) { $tempLegendArray[] = $tempDataLegend; if (isset($tempDataValue) && is_numeric($tempDataValue)) { $tempDataArray[] = $tempDataValue; } else { return FALSE; } } $MyData = new pData(); $MyData->addPoints($tempDataArray, 'Values'); $MyData->setSerieDescription("Values", "Valeurs"); $MyData->addPoints($tempLegendArray, 'Label'); $MyData->setAbscissa("Label"); /* On crée l'objet pChart */ if (isset($data['settings']['width'])) { $width = $data['settings']['width']; } else { $width = 600; } if (isset($data['settings']['height'])) { $height = $data['settings']['height']; } else { $height = 300; } $myPicture = new pImage($width, $height, $MyData, TRUE); /* On crée l'objet pPie */ $PieChart = new pPie($myPicture, $MyData); $myPicture->setFontProperties(array("FontName" => PLUGIN_PATH . 'core/pChart2.1.4/fonts/MankSans.ttf', "FontSize" => 13, "R" => 223, "G" => 223, "B" => 223)); $PieChart->draw3DPie($width / 2, ($height - 75) / 2, array("Radius" => 100, "DataGapAngle" => 12, "WriteValues" => TRUE, "DataGapRadius" => 10, "Border" => TRUE)); $myPicture->setFontProperties(array("FontName" => PLUGIN_PATH . 'core/pChart2.1.4/fonts/MankSans.ttf', "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); $PieChart->drawPieLegend(10, $height - 75, array("Style" => LEGEND_ROUND, "Mode" => LEGEND_VERTICAL)); $myPicture->render($filePath); return $filePathURI; } } else { return FALSE; } }
$MyData->addPoints(array("failed", "error", "passed"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(300, 250, $MyData, TRUE); /* Draw a solid background */ $Settings = array("R" => 220, "G" => 220, "B" => 220); $myPicture->drawFilledRectangle(0, 0, 300, 250, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 299, 249, array("R" => 162, "G" => 181, "B" => 205)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Forgotte.ttf", "FontSize" => 11)); $myPicture->drawText(145, 25, "Compliance Level Distribution", array("R" => 75, "G" => 75, "B" => 75, "FontSize" => 14, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Define the slice color */ $PieChart->setSliceColor(0, array("R" => 255, "G" => 0, "B" => 0)); $PieChart->setSliceColor(1, array("R" => 255, "G" => 165, "B" => 0)); $PieChart->setSliceColor(2, array("R" => 255, "G" => 255, "B" => 0)); $PieChart->setSliceColor(3, array("R" => 0, "G" => 175, "B" => 80)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10)); /* Draw an AA pie chart */ $PieChart->draw3DPie(150, 125, array("Radius" => 125, "WriteValues" => TRUE, "DataGapAngle" => 5, "DataGapRadius" => 5, "Border" => TRUE)); /* Enable shadow computing */ //$myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); /* Write the legend */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Forgotte.ttf", "FontSize" => 14)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Forgotte.ttf", "FontSize" => 14, "R" => 75, "G" => 75, "B" => 75)); $PieChart->drawPieLegend(55, 210, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL));
public function drawImage() { $qr_result = $this->values; //var_dump($qr_result);die(); $va_columns = $this->parameters["columns"]; $width = $this->parameters["width"]; $format = $this->parameters["format"]; $va_charting_columns = $this->parameters["charting_columns"]; $va_chart_types = $this->parameters["chart_types"]; $qr_result->seek(); if ($qr_result->numRows() == 0) { //if no result nothing to do return false; } // Loading chart format specifications // TODO : this coding part should be out of this function, sending values in 1 parameter if (is_array($va_chart_types)) { foreach ($va_chart_types as $type => $settings) { if ($type == $format) { $chart_type = $settings["googletype"]; $message = $settings["message"]; } } } /* Create and populate the pData object */ $MyData = new pData(); // Fulfillment of the results $va_row_no = 0; $va_content = array(); while ($qr_result->nextRow()) { $va_column_no = 0; foreach ($va_columns as $va_column => $va_column_label) { // only render columns specified in XML field charting_columns if (in_array($va_column_label, $va_charting_columns)) { $va_content[$va_column_label][$va_row_no] = $qr_result->get($va_column_label); $va_column_no++; } } $va_row_no++; } //var_dump($va_content); $va_row_no = 0; foreach ($va_charting_columns as $va_column_label) { //print "MyData->addPoints(\"".implode("\",\"",$va_content[$va_column_label])."\",\"".$va_column_label."\");<br/>"; $MyData->addPoints($va_content[$va_column_label], $va_column_label); if ($va_row_no == 0) { //print "MyData->setAbscissa(\"Labels\")<br/>"; $MyData->setAbscissa($va_column_label); } else { //print "MyData->setSerieDescription(\"".$va_column_label."\",\"".$va_column_label."\");<br/>"; $MyData->setSerieDescription($va_column_label, $va_column_label); } $va_row_no++; } /* Create the pChart object */ $myPicture = new pImage($width, $width / 2, $MyData); /* Set the common properties */ $myPicture->setFontProperties(array("FontName" => __CA_STATISTICSVIEWER_CLASS_DIR__ . "/fonts/verdana.ttf", "FontSize" => 0.014 * $width, "R" => 80, "G" => 80, "B" => 80)); $RectangleSettings = array("R" => 200, "G" => 200, "B" => 200); $myPicture->drawRectangle(1, 1, $width - 1, $width / 2 - 1, $RectangleSettings); $myPicture->setGraphArea($width / 9, $width / 10, $width * 0.75, $width * 0.4); // if not pie, draw the legend if ($format != "pie") { $myPicture->drawLegend($width * 0.8, $width * 0.05, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); } switch ($format) { case "bar": $myPicture->drawScale(array("Pos" => SCALE_POS_TOPBOTTOM, "DrawSubTicks" => FALSE, "RemoveYAxis" => TRUE, "GridAlpha" => 90, "DrawXLines" => FALSE)); $myPicture->drawBarChart(); break; case "column": $myPicture->drawScale(array("DrawSubTicks" => FALSE, "RemoveYAxis" => TRUE, "GridAlpha" => 90, "DrawXLines" => FALSE)); $myPicture->drawBarChart(); break; case "step": $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawStepChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; case "area": $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawAreaChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; case "pie": $PieChart = new pPie($myPicture, $MyData); $PieChart->draw2DPie(0.4 * $width, 0.25 * $width, array("WriteValues" => PIE_VALUE_PERCENTAGE, "ValueR" => 95, "ValueG" => 95, "ValueB" => 95, "ValuePadding" => 0.03 * $width, "Radius" => 0.16 * $width, "SecondPass" => TRUE, "Border" => TRUE, "Precision" => 0)); $myPicture->setShadow(FALSE); $myPicture->setFontProperties(array("FontName" => __CA_STATISTICSVIEWER_CLASS_DIR__ . "/fonts/verdana.ttf", "FontSize" => 0.018 * $width, "R" => 80, "G" => 80, "B" => 80)); $PieChart->drawPieLegend(0.8 * $width, 0.05 * $width, array("Style" => LEGEND_NOBORDER, "BoxSize" => $width / 60, "FontR" => 0, "FontG" => 0, "FontB" => 0)); break; case "line": default: $myPicture->drawScale(array("DrawXLines" => FALSE, "DrawYLines" => ALL, "GridR" => 127, "GridG" => 127, "GridB" => 127)); $myPicture->drawLineChart(array("DisplayValues" => TRUE, "DisplayColor" => DISPLAY_AUTO)); break; } /* Render the picture (choose the best way) */ $myPicture->autoOutput(); }
/* Define the absissa serie */ $MyData->addPoints(array("<10", "10<>20", "20<>40", "40<>60", "60<>80", ">80"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(300, 260, $MyData); /* Retrieve the image map */ if (isset($_GET["ImageMap"]) || isset($_POST["ImageMap"])) { $myPicture->dumpImageMap("ImageMap2DPieChart", IMAGE_MAP_STORAGE_FILE, "2DPieChart", "../pChart2.1.4/tmp"); } /* Set the image map name */ $myPicture->initialiseImageMap("ImageMap2DPieChart", IMAGE_MAP_STORAGE_FILE, "2DPieChart", "../pChart2.1.4/tmp"); /* Draw a solid background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 300, 300, $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, 300, 260, DIRECTION_VERTICAL, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 299, 259, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => FONT_PATH . "/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); /* Create the pPie object */ $Settings = array("RecordImageMap" => TRUE); $PieChart = new pPie($myPicture, $MyData, $Settings); /* Draw an AA pie chart */ $PieSettings = array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE, "RecordImageMap" => TRUE); $PieChart->draw2DPie(160, 125, $PieSettings); /* Render the picture (choose the best way) */ $myPicture->autoOutput("../tmp/2DPieChart.png");
$MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(300, 260, $MyData); /* Draw a solid background */ $Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107); $myPicture->drawFilledRectangle(0, 0, 300, 300, $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, 300, 260, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 300, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 299, 259, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "pPie - Draw 2D pie charts", array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ $PieChart->draw2DPie(160, 140, array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); /* Write the legend box */ $myPicture->setShadow(FALSE); $PieChart->drawPieLegend(15, 40, array("Alpha" => 20)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.draw2DPie.labels.png");
/* Draw the background */ $Settings = array("R" => 39, "G" => 43, "B" => 48, "Dash" => 1, "DashR" => 122, "DashG" => 130, "DashB" => 136); $myPicture->drawFilledRectangle(0, 0, 700, 330, $Settings); /* Overlay with a gradient */ $Settings = array("StartR" => 39, "StartG" => 43, "StartB" => 48, "EndR" => 122, "EndG" => 130, "EndB" => 136, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 330, 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, 329, array("R" => 0, "G" => 0, "B" => 0)); /* Write the chart title */ $myPicture->setFontProperties(array("FontName" => "pChart/fonts/Silkscreen.ttf", "FontSize" => 6, "R" => 255, "G" => 255, "B" => 255)); $myPicture->drawText(10, 13, "Repartition des surfaces (m carre)", array("R" => 255, "G" => 255, "B" => 255)); /* Define the default font */ $myPicture->setFontProperties(array("FontName" => "pChart/fonts/verdana.ttf", "FontSize" => 10)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20)); /* Draw the Pie Chart */ $PieChart = new pPie($myPicture, $MyData); $PieChart->draw2DPie(350, 165, array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); if ($consult_date != "Donnée actuelle") { $myPicture->Render("images/rds_graph_render_{$consult_date}.png"); } else { $myPicture->Render("images/rds_graph_render.png"); } } else { $error = 1; } } } catch (Exception $e) { // Catch des erreurs et écriture dans le fichier de log require 'error_log.php'; }
/** * 绘制图表并生成图片 * @method drawChart * @return [type] [description] */ protected function drawChart($data_arr, $lab_arr, $pic_name) { /* pChart library inclusions */ include "libs/pChart2.1.4/class/pData.class.php"; include "libs/pChart2.1.4/class/pDraw.class.php"; include "libs/pChart2.1.4/class/pPie.class.php"; include "libs/pChart2.1.4/class/pImage.class.php"; /* pData object creation */ $MyData = new \pData(); /* Data definition */ $MyData->addPoints($data_arr, "Value"); /* Labels definition */ $MyData->addPoints($lab_arr, "Legend"); $MyData->setAbscissa("Legend"); /* Create the pChart object */ $myPicture = new \pImage(500, 150, $MyData); /* Draw a gradient background */ $myPicture->drawGradientArea(0, 0, 500, 150, DIRECTION_HORIZONTAL, array("StartR" => 220, "StartG" => 220, "StartB" => 220, "EndR" => 180, "EndG" => 180, "EndB" => 180, "Alpha" => 100)); /* Add a border to the picture */ // $myPicture->drawRectangle(0,0,399,149,array("R"=>0,"G"=>0,"B"=>0)); /* Create the pPie object */ $PieChart = new \pPie($myPicture, $MyData); /* Enable shadow computing */ $myPicture->setShadow(FALSE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => __DIR__ . "/libs/pChart2.1.4/fonts/msyh.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Draw a splitted pie chart */ $PieChart->draw3DPie(250, 100, array("Radius" => 80, "DrawLabels" => TRUE, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => FALSE)); /* Render the picture (choose the best way) */ $myPicture->autoOutput(public_path() . '/pictures/' . $pic_name); }
$MyData->addPoints(array(50, 2, 3, 4, 7, 10, 25, 48, 41, 10), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("A0", "B1", "C2", "D3", "E4", "F5", "G6", "H7", "I8", "J9"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(400, 400, $MyData); /* Draw a solid 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" => 100)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 399, 399, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "pPie - Draw 3D ring charts", array("R" => 255, "G" => 255, "B" => 255)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 10, "R" => 80, "G" => 80, "B" => 80)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ $PieChart->draw3DRing(200, 200, array("DrawLabels" => TRUE, "LabelStacked" => TRUE, "Border" => TRUE)); /* Write the legend box */ $PieChart->drawPieLegend(80, 360, array("Mode" => LEGEND_HORIZONTAL, "Style" => LEGEND_NOBORDER, "Alpha" => 20)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.draw3DRing.png");
function pieGen($stats, $mode) { global $centreon_path; // Create and populate the pData object $MyData = new pData(); // print_r($stats["average"]); $arrPoints = array(); $i = 0; // Host groups if ($mode == "hgs") { $MyData->addPoints(array($stats["average"]["UP_TP"], $stats["average"]["DOWN_TP"], $stats["average"]["UNDETERMINED_TP"], $stats["average"]["UNREACHABLE_TP"], $stats["average"]["MAINTENANCE_TP"]), "Hostgroups"); $MyData->setSerieDescription("Hostgroups", "Hostgroups"); $arrPoints = array("Up", "Down", "Undeterminded", "Unreachable", "Schedule Downtime"); // Define the absissa serie $MyData->addPoints($arrPoints, "Labels"); $MyData->setAbscissa("Labels"); // Create the pChart object $myPicture = new pImage(120, 120, $MyData, TRUE); // Create the pPie object $PieChart = new pPie($myPicture, $MyData); $i = 0; /* Define the slice color */ if ($stats["average"]["UP_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 25, "G" => 238, "B" => 17)); // UP $i++; } if ($stats["average"]["DOWN_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 249, "G" => 30, "B" => 5)); // DOWN $i++; } if ($stats["average"]["UNDETERMINED_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 204, "G" => 248, "B" => 255)); // UNDETERMINED //$PieChart->setSliceColor($i,array("R"=>240,"G"=>240,"B"=>240)); $i++; } if ($stats["average"]["UNREACHABLE_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 130, "G" => 207, "B" => 216)); // UNREACHABLE $i++; } if ($stats["average"]["MAINTENANCE_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 204, "G" => 153, "B" => 255)); // MAINTENANCE $i++; } } // Service Groups if ($mode == "sgs") { $MyData->addPoints(array($stats["average"]["OK_TP"], $stats["average"]["WARNING_TP"], $stats["average"]["CRITICAL_TP"], $stats["average"]["UNKNOWN_TP"], $stats["average"]["MAINTENANCE_TP"], $stats["average"]["UNDETERMINED_TP"]), "Servicegroups"); $MyData->setSerieDescription("Servicegroups", "Servicegroups"); $arrPoints = array("Ok", "Warning", "Critical", "Unknown", "Schedule Downtime", "Undeterminded"); // Define the absissa serie $MyData->addPoints($arrPoints, "Labels"); $MyData->setAbscissa("Labels"); // Create the pChart object $myPicture = new pImage(120, 120, $MyData, TRUE); // Create the pPie object $PieChart = new pPie($myPicture, $MyData); /* Define the slice color */ if ($stats["average"]["OK_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 13, "G" => 235, "B" => 58)); // OK $i++; } if ($stats["average"]["WARNING_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 248, "G" => 199, "B" => 6)); // DOWN $i++; } if ($stats["average"]["CRITICAL_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 249, "G" => 30, "B" => 5)); // DOWN $i++; } if ($stats["average"]["UNKNOWN_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 220, "G" => 218, "B" => 218)); // UNKNOWN $i++; } if ($stats["average"]["MAINTENANCE_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 204, "G" => 153, "B" => 255)); // MAINTENANCE $i++; } if ($stats["average"]["UNDETERMINED_TP"] > 0) { $PieChart->setSliceColor($i, array("R" => 204, "G" => 248, "B" => 255)); // UNDETERMINED //$PieChart->setSliceColor($i,array("R"=>240,"G"=>240,"B"=>240)); // UNDETERMINED $i++; } } $Settings = array("R" => 255, "G" => 255, "B" => 255); $myPicture->drawFilledRectangle(0, 0, 120, 120, $Settings); // Enable shadow computing // $myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); // Draw a splitted pie chart $PieChart->draw3DPie(60, 70, array("Radius" => 50, "DataGapAngle" => 8, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 0, "BorderG" => 0, "BorderB" => 0)); /* Render the picture */ // $pie_file = tempnam( "/tmp" , "reportreon_pie_" ); $pie_file = tempnam($centreon_path . "/www/modules/pdfreports/generatedFiles/tmp", "reportreon_pie_"); $myPicture->render($pie_file . ".png"); @unlink($pie_file); return $pie_file . ".png"; }
foreach ($os_list as $os_name => $count) { $os_name = trim($os_name); if (trim($os_name) == '') { $os_name = 'Unknown'; } array_push($points_labels, $os_name . ' (' . sprintf("%01.2f", $count / $sum * 100) . '%)'); array_push($points_values, $count); } $MyDataOS = new pData(); $MyDataOS->addPoints($points_values, "OS values"); $MyDataOS->setSerieDescription("OS values", "Application A"); $MyDataOS->addPoints($points_labels, "Labels"); $MyDataOS->setAbscissa("Labels"); $myPicture = create_common_image($lang['OS popularity'], 680, 250, $MyDataOS, 'pie'); $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 50)); $PieChart = new pPie($myPicture, $MyDataOS); $PieChart->draw2DPie(220, 125, array("ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 80, "ValuePosition" => PIE_VALUE_OUTSIDE, "LabelStacked" => TRUE, "DrawLabels" => TRUE, "DataGapAngle" => 8, "DataGapRadius" => 6, "Border" => TRUE, "BorderR" => 255, "BorderG" => 255, "BorderB" => 255)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20)); $myPicture->drawText(220, 230, "Operating systems", array("DrawBox" => TRUE, "BoxRounded" => TRUE, "R" => 0, "G" => 0, "B" => 0, "Align" => TEXT_ALIGN_TOPMIDDLE)); // Additional OS statistics $win64_list = array(); if (!$pony_db->get_64bit_stats($win64_list)) { die; } if (!isset($win64_list['0'])) { $win64_list['0'] = '0'; } if (!isset($win64_list['1'])) { $win64_list['1'] = '0'; } $admin_list = array();