/** * * @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; }
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"); }
/** * 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 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"); }
/* 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); */ /* Render the picture (choose the best way) */ $myPicture->autoOutput("3DPie.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)); }
/* 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) */ $myPicture->autoOutput("pictures/example.draw2DPie.png");
$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");
$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");
function pch_pie_graph($graph_type, $data_values, $legend_values, $width, $height, $font, $water_mark, $font_size) { /* CAT:Pie charts */ /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($data_values, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($legend_values, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage($width, $height, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size, "R" => 80, "G" => 80, "B" => 80)); $water_mark_height = 0; $water_mark_width = 0; if (!empty($water_mark)) { $size_water_mark = getimagesize($water_mark); $water_mark_height = $size_water_mark[1]; $water_mark_width = $size_water_mark[0]; $myPicture->drawFromPNG($width - $water_mark_width, $height - $water_mark_height - 50, $water_mark); } /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ switch ($graph_type) { case "pie2d": $PieChart->draw2DPie($width / 4, $height / 2, array("DataGapAngle" => 0, "DataGapRadius" => 0, "Border" => FALSE, "BorderR" => 200, "BorderG" => 200, "BorderB" => 200, "Radius" => $width / 4, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "WriteValues" => TRUE)); break; case "pie3d": $PieChart->draw3DPie($width / 4, $height / 2, array("DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE, "Radius" => $width / 4, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "WriteValues" => TRUE)); break; } /* Write down the legend next to the 2nd chart*/ //Calculate the bottom margin from the size of string in each index $max_chars = 0; foreach ($legend_values as $string_legend) { if (empty($string_legend)) { continue; } $len = strlen($string_legend); if ($len > $max_chars) { $max_chars = $len; } } $legend_with_aprox = 32 + 7 * $max_chars; $PieChart->drawPieLegend($width - $legend_with_aprox, 5, array("R" => 255, "G" => 255, "B" => 255, "BoxSize" => 10)); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 3, "Y" => 3, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Render the picture */ $myPicture->stroke(); }
$myPicture->drawText($width - $marg - 2, $marg + 2, $pieValueKeyLabel . ":" . $pieValueKey . " 总量:" . array_sum($arrPieValues), array("Align" => TEXT_ALIGN_TOPRIGHT, "BorderOffset" => 5, "R" => 55, "G" => 55, "B" => 55, "DrawBox" => TRUE, "BoxRounded" => TRUE, "BoxR" => 100, "BoxG" => 100, "BoxB" => 100, "BoxAlpha" => 20)); } $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 4, "R" => 150, "G" => 150, "B" => 150, "Alpha" => 80)); $pieSettings = array("DrawLabels" => TRUE, "LabelStacked" => FALSE, "LabelColor" => PIE_LABEL_COLOR_MANUAL, "WriteValues" => $WriteValues, "ValuePosition" => PIE_VALUE_INSIDE); // 画2D饼图 if ($chartType == 'pie2d') { $PieChart->draw2DPie($width * 0.4, $height * 0.53, array("Radius" => min($height, $width * 0.7) * 0.3, "Border" => TRUE, "ValueR" => 255, "ValueG" => 255, "ValueB" => 255, "ValueAlpha" => 100, "LabelStacked" => FALSE) + $pieSettings); } // 画3D饼图 if ($chartType == 'pie3d') { $PieChart->draw3DPie($width * 0.5, $height * 0.57, array("Radius" => min($height, $width * 0.7) * 0.4, "SliceHeight" => min($height, $width * 0.7) * 0.08, "DataGapAngle" => 5, "DataGapRadius" => min($height, $width * 0.7) * 0.02, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 60, "LabelStacked" => FALSE) + $pieSettings); } /* Draw Pie Legend */ // 根据设置显示图例,1:纵向,2:横向,否则不显示 if ($legend == 1) { $PieChart->drawPieLegend($width * 0.9 - 60, $marg + $font_t * 3, array("Align" => TEXT_ALIGN_TOPRIGHT, "Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } if ($legend == 2) { $PieChart->drawPieLegend($marg, $height - $marg - $font * 2, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); } } else { $nSerie = 0; if (!isset($chart_limit)) { $chart_limit = 1000; } $plotShapes = array(SERIE_SHAPE_FILLEDCIRCLE, SERIE_SHAPE_FILLEDTRIANGLE, SERIE_SHAPE_FILLEDSQUARE, SERIE_SHAPE_FILLEDDIAMOND); reset($arrFields); while (list($idx, $field) = each($arrFields)) { if (!isset($chart_cols) or $idx == 0 or in_array($idx, $chart_cols)) { $arrSeries[] = $field; $myData->addPoints(array_reverse(array_slice($arrCols[$field], 0, $chart_limit)), $field);
static function makePieTopEditors($title, $total, &$data, $lang) { global $wt, $I18N; $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"; } $i = 0; foreach ($data as $user => $details) { $val = number_format($details["all"] / $total * 100, 1); $users[] = $user . " · {$val}%"; $values[] = $val; $colors[] = str_replace("#", "", self::GetColorList($i)); $i++; if ($i == 9) { break; } } $users[] = $I18N->msg("others"); $colors[] = str_replace("#", "", self::GetColorList(100)); $values[] = 100 - array_sum($values); $MyData = new pData(); $MyData->addPoints($values, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); $MyData->addPoints($users, "Labels"); $MyData->setAbscissa("Labels"); $myPicture = new pImage(500, 250, $MyData, TRUE); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 9)); $myPicture->drawText(150, 16, $title, array("R" => 0, "G" => 0, "B" => 0)); $PieChart = new pPie($myPicture, $MyData); foreach ($colors as $i => $color) { $PieChart->setSliceColor($i, self::hex2rgb($color, 200, true)); } $PieChart->draw2DPie(150, 140, array("Radius" => 100, "SecondPass" => true, "DrawLabels" => false, "Border" => TRUE)); $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => 9, "R" => 34, "G" => 34, "B" => 34)); $PieChart->drawPieLegend(320, 55, array("Style" => LEGEND_NOBORDER, "BoxSize" => 12, "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; }
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); }
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'); }
include "../class/pData.class.php"; include "../class/pDraw.class.php"; include "../class/pPie.class.php"; include "../class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints(array(40, 50), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("MANE", "FETO"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(600, 200, $MyData, TRUE); $Settings = array("R" => 240, "G" => 240, "B" => 240); $myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 599, 199, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../fonts/GeosansLight.ttf", "FontSize" => 15, "R" => 0, "G" => 0, "B" => 0)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw a splitted pie chart */ $PieChart->draw3DPie(300, 125, array("WriteValues" => TRUE, "Border" => TRUE, 'ValueR' => 0, 'ValueG' => 0, 'ValueB' => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/GeosansLight.ttf", "FontSize" => 12)); $myPicture->drawText(230, 25, "Divisaun Rejistu FETO no MANE", array("R" => 0, "G" => 0, "B" => 0)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../fonts/GeosansLight.ttf", "FontSize" => 10, "R" => 0, "G" => 0, "B" => 0)); $PieChart->drawPieLegend(500, 40, array("Style" => LEGEND_NOBORDER)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.draw3DPie.png");
/* Overlay with a gradient */ $Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50); $myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings); $myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80)); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(10, 13, "drawPieLegend - Draw pie charts legend", 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" => 150, "G" => 150, "B" => 150, "Alpha" => 100)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw two AA pie chart */ $PieChart->draw2DPie(200, 100, array("Border" => TRUE)); $PieChart->draw2DPie(440, 115, array("Border" => TRUE)); /* Write down the legend next to the 2nd chart*/ $PieChart->drawPieLegend(550, 70); /* Write a legend box under the 1st chart */ $myPicture->setFontProperties(array("FontName" => "../fonts/pf_arma_five.ttf", "FontSize" => 6)); $PieChart->drawPieLegend(90, 176, array("Style" => LEGEND_BOX, "Mode" => LEGEND_HORIZONTAL)); /* Write the bottom legend box */ $myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawGradientArea(1, 200, 698, 228, DIRECTION_VERTICAL, array("StartR" => 247, "StartG" => 247, "StartB" => 247, "EndR" => 217, "EndG" => 217, "EndB" => 217, "Alpha" => 20)); $myPicture->drawLine(1, 199, 698, 199, array("R" => 100, "G" => 100, "B" => 100, "Alpha" => 20)); $myPicture->drawLine(1, 200, 698, 200, array("R" => 255, "G" => 255, "B" => 255, "Alpha" => 20)); $PieChart->drawPieLegend(10, 210, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("pictures/example.drawPieLegend.png");
/* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($number, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($maps, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(600, 300, $MyData, TRUE); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../pchart/fonts/Forgotte.ttf", "FontSize" => 12)); $myPicture->drawText(170, 24, "Maps played in percent from greatest to least.", array("R" => 150, "G" => 150, "B" => 150)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../pchart/fonts/pf_arma_five.ttf", "FontSize" => 6, "R" => 150, "G" => 150, "B" => 150)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ $PieChart->draw2DRing(300, 150, array("WriteValues" => TRUE, "ValueR" => 150, "ValueG" => 150, "ValueB" => 150, "Border" => TRUE)); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../pchart/fonts/pf_arma_five.ttf", "FontSize" => 6, "R" => 150, "G" => 150, "B" => 150)); /* Write the legend box */ $myPicture->setShadow(FALSE); $PieChart->drawPieLegend(480, 10, array("Alpha" => 0)); /* Render the picture */ $myPicture->stroke($BrowserExpire = TRUE); } } else { // start outputting the image header("Content-type: image/png"); echo file_get_contents('./images/error.png'); }
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"); }
/** * 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; } }
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; }
} 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($width - 100, 30, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); } else { $graphImage->drawLegend($width - 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->autoOutput("pictures/example.drawBarChart.simple.png"); function htmltorgb($color) { if ($color[0] == '#') { $color = substr($color, 1); } if (strlen($color) == 6) { list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); } elseif (strlen($color) == 3) { list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); } else {
$chart_params = params_decode($_GET['params']); /* pChart library inclusions */ include "pchart/class/pData.class.php"; include "pchart/class/pDraw.class.php"; include "pchart/class/pPie.class.php"; include "pchart/class/pImage.class.php"; /* Create and populate the pData object */ $MyData = new pData(); foreach ($chart_params['data'] as $dp) { $MyData->addPoints($dp[$chart_params['ejex']], "ejex"); $MyData->addPoints($dp[$chart_params['ejey']], "ejey"); } $MyData->setSerieDescription("ejey", $chart_params['ejey']); /* Define the absissa serie */ $MyData->setAbscissa("ejex"); //$MyData->loadPalette("pchart/palettes/navy.color", TRUE); /* Create the pChart object */ $myPicture = new pImage(720, 380, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "pchart/fonts/verdana.ttf", "FontSize" => 16, "R" => 0, "G" => 0, "B" => 200)); /* 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(290, 200, array("WriteValues" => PIE_VALUE_PERCENTAGE, "Radius" => 240, "DataGapAngle" => 12, "DataGapRadius" => 10, "Border" => TRUE, "ValueR" => 10, "ValueG" => 10, "ValueB" => 10)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "pchart/fonts/verdana.ttf", "FontSize" => 12, "R" => 0, "G" => 0, "B" => 0)); $PieChart->drawPieLegend(520, 15, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_VERTICAL)); /* Render the picture (choose the best way) */ $myPicture->stroke();
public function generate_chart($chart_name) { include_once "pchart/class/pPie.class.php"; global $wgBugzillaChartStorage; global $wgBugzillaFontStorage; // TODO: Make all this size stuff trivial for other // graph types to plug into switch ($this->_get_size()) { case 'small': $imgX = 200; $imgY = 65; $radius = 30; $font = 6; break; case 'medium': $imgX = 400; $imgY = 125; $radius = 60; $font = 7; break; case 'large': default: $imgX = 500; $imgY = 245; $radius = 120; $font = 9; } $padding = 5; $startX = isset($startX) ? $startX : $radius; $startY = isset($startY) ? $startY : $radius; $pData = new pData(); $pData->addPoints($this->query->data['data'], 'Counts'); $pData->setAxisName(0, 'Bugs'); $pData->addPoints($this->query->data['x_labels'], "Bugs"); $pData->setSerieDescription("Bugs", "Bugs"); $pData->setAbscissa("Bugs"); $pImage = new pImage($imgX, $imgY, $pData); $pImage->setFontProperties(array('FontName' => $wgBugzillaFontStorage . '/verdana.ttf', 'FontSize' => $font)); $pPieChart = new pPie($pImage, $pData); $pPieChart->draw2DPie($startX, $startY, array("Radius" => $radius, "ValuePosition" => PIE_VALUE_INSIDE, "WriteValues" => PIE_VALUE_NATURAL, "DrawLabels" => FALSE, "LabelStacked" => TRUE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "Border" => TRUE)); // Legend $pImage->setShadow(FALSE); $pPieChart->drawPieLegend(2 * $radius + 2 * $padding, $padding, array("Alpha" => 20)); $pImage->render($wgBugzillaChartStorage . '/' . $chart_name . '.png'); $cache = $this->_getCache(); $cache->set($chart_name, $chart_name . '.png'); return $chart_name; }
/** * 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); }
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(); }