/** * * @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"); }
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 }
/** *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 . '">'; }
/** * 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; } }
<?php /* CAT:Pie charts */ /* pChart library inclusions */ 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, 30, 20), "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints(array("A", "B", "C"), "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(240, 180, $MyData, TRUE); /* Set the default font properties */ $myPicture->setFontProperties(array("FontName" => "../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" => 10, "DataGapRadius" => 6, "Border" => TRUE)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../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->autoOutput("pictures/example.draw3DPie.transparent.png");
$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 / 2,$height / 2,80,array("DrawLabels"=>TRUE,"LabelStacked"=>TRUE,"Border"=>TRUE)); $pie->draw2DPie($width / 2, $height / 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($width / 2, $height / 2, 80, array("SecondPass" => FALSE)); break; case "STACKEDBAR": case "BAR": if ($stackeddrawn) { break; } if ($barexists) { foreach ($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);
/** * 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); }
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); }
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; }
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");
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(); }
$MyData = new pData(); $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(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)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Draw an AA pie chart */ $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.draw3DPie.labels.png");
/* Create the pChart object */ $myPicture = new pImage(430, 200, $MyData, TRUE); /* Draw a solid background */ $Settings = array("R" => 220, "G" => 220, "B" => 220); $myPicture->drawFilledRectangle(0, 0, 430, 200, $Settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, 429, 199, array("R" => 162, "G" => 181, "B" => 205)); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Silkscreen.ttf", "FontSize" => 6)); $myPicture->drawText(125, 25, "{$title}", array("R" => 75, "G" => 75, "B" => 75)); /* 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" => 230, "G" => 230, "B" => 250)); $PieChart->setSliceColor(1, array("R" => 255, "G" => 0, "B" => 0)); $PieChart->setSliceColor(2, array("R" => 255, "G" => 165, "B" => 0)); $PieChart->setSliceColor(3, array("R" => 255, "G" => 255, "B" => 0)); /* Draw an AA pie chart */ $PieChart->draw3DPie(210, 100, array("WriteValues" => TRUE, "DataGapAngle" => 10, "DataGapRadius" => 6, "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/pf_arma_five.ttf", "FontSize" => 6)); $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20)); /* Write the legend box */ $myPicture->setFontProperties(array("FontName" => "../../pChart/fonts/Silkscreen.ttf", "FontSize" => 6, "R" => 75, "G" => 75, "B" => 75)); $PieChart->drawPieLegend(85, 165, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("img.png");
function drk_start() { global $db, $darkcoin; $drk_price = file_get_contents("http://midas-bank.com/price.php?name=DRK"); $hash_block = $darkcoin->getbestblockhash(); $info_block = $darkcoin->getblock($hash_block); $tx = $info_block["tx"][0]; $diff = round($info_block["difficulty"]); $last_block = $block_id = $info_block["height"]; $block_time = $info_block["time"]; $encode_tx = $darkcoin->getrawtransaction($tx); $tx_info = $darkcoin->decoderawtransaction($encode_tx); $address = $tx_info["vout"][0]["scriptPubKey"]["addresses"][0]; // Определеяем P2Pool $p2p = json_decode(file_get_contents("http://eu.p2pool.pl:7903/recent_blocks"), TRUE); foreach ($p2p as $data) { if ($block_id == $data["number"]) { $address = 'P2Pool'; break; } } // Записываем данные в базу $query_select = $db->prepare("SELECT * FROM `address` WHERE `address` =:address"); $query_select->bindParam(':address', $address, PDO::PARAM_STR); $query_select->execute(); if ($query_select->rowCount() != 1) { $query_insert = $db->prepare("INSERT INTO `address` (`address`) VALUES (:address)"); $query_insert->bindParam(':address', $address, PDO::PARAM_STR); $query_insert->execute(); } // Записываем статистику по блокам $query_select = $db->prepare("SELECT * FROM `data` WHERE `bid` =:bid"); $query_select->bindParam(':bid', $block_id, PDO::PARAM_STR); $query_select->execute(); if ($query_select->rowCount() == 1) { echo "Find new block... \n"; return; } else { echo "[36mBlock: {$block_id} | Find: {$address} | Time: {$block_time} | Diff: {$diff} | Price: {$drk_price}\$ [0m \n"; $query_insert = $db->prepare("INSERT INTO `data` (`bid`, `diff`, `address`, `time`) VALUES (:bid, :diff, :address, :time)"); $query_insert->bindParam(':bid', $block_id, PDO::PARAM_STR); $query_insert->bindParam(':diff', $diff, PDO::PARAM_STR); $query_insert->bindParam(':address', $address, PDO::PARAM_STR); $query_insert->bindParam(':time', $block_time, PDO::PARAM_STR); $query_insert->execute(); $lastId = $db->lastInsertId(); } $k = 0; $query_select = $db->prepare("SELECT * FROM `data` WHERE `time` > UNIX_TIMESTAMP()-86400"); $query_select->execute(); $all_data = $query_select->rowCount(); $query_select = $db->prepare("SELECT SUM(diff) FROM `data` WHERE `time` > UNIX_TIMESTAMP()-86400"); $query_select->execute(); $row = $query_select->fetch(); $diff_sum = $row['SUM(diff)']; $avg_diff = $diff_sum / $all_data; $query_select = $db->prepare("SELECT * FROM `address`"); $query_select->execute(); if ($query_select->rowCount() == 0) { return; } while ($row = $query_select->fetch()) { $query_data = $db->prepare("SELECT * FROM `data` WHERE `address` = :address AND `time` > UNIX_TIMESTAMP()-86400"); $query_data->bindParam(':address', $row['address'], PDO::PARAM_STR); $query_data->execute(); if ($row['address'] == 'P2Pool') { $row['label'] = 'P2Pool'; } if ($query_data->rowCount() / $all_data * 100 < 3 || empty($row['label'])) { $k = $k + $query_data->rowCount(); continue; } $arr_count[] = $query_data->rowCount(); $arr_label[] = $row['label']; } if ($k > 0) { $arr_label[] = 'Other'; $arr_count[] = $k; } array_multisort($arr_count, SORT_DESC, $arr_label); /* Create and populate the pData object */ $MyData = new pData(); $MyData->addPoints($arr_count, "ScoreA"); $MyData->setSerieDescription("ScoreA", "Application A"); /* Define the absissa serie */ $MyData->addPoints($arr_label, "Labels"); $MyData->setAbscissa("Labels"); /* Create the pChart object */ $myPicture = new pImage(720, 400, $MyData, TRUE); $myPicture->Antialias = TRUE; /* Draw a solid background */ $Settings = array("R" => 255, "G" => 255, "B" => 255); $myPicture->drawFilledRectangle(0, 0, 920, 400, $Settings); /* Write the picture title */ $myPicture->setFontProperties(array("FontName" => "/var/www/midas/root/fonts/verdana.ttf", "FontSize" => 14)); $myPicture->drawText(0, 20, "At block: {$last_block}", array("R" => 0, "G" => 0, "B" => 0)); $myPicture->drawText(210, 24, "Difficulty: {$diff}", array("R" => 0, "G" => 0, "B" => 0)); $myPicture->drawText(390, 24, "Avg difficulty: " . round($avg_diff), array("R" => 0, "G" => 0, "B" => 0)); $myPicture->drawText(600, 23, "Price: {$drk_price}\$", array("R" => 0, "G" => 0, "B" => 0)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Enable shadow computing */ $myPicture->setShadow(TRUE, array("X" => 2, "Y" => 2, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw a splitted pie chart */ $myPicture->setFontProperties(array("FontName" => "/var/www/midas/root/fonts/tahoma.ttf", "FontSize" => 10)); $PieChart->draw3DPie(340, 220, array("WriteValues" => TRUE, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "Radius" => 225, "DataGapAngle" => 4, "DataGapRadius" => 6, "DrawLabels" => TRUE, "Border" => TRUE)); /* Render the picture (choose the best way) */ $myPicture->Render("/var/www/midas/root/stat/drk.png"); unset($data); $data = ['num' => $last_block, 'diff' => round($avg_diff)]; $query = $db->prepare("SELECT * FROM `params` WHERE `key` = 'block'"); $query->execute(); if ($query->rowCount() != 1) { $query = $db->prepare("INSERT INTO `params` (`key`, `value`) VALUES ('block', :value)"); $query->bindParam(':value', json_encode($data), PDO::PARAM_STR); $query->execute(); } else { $query = $db->prepare("UPDATE `params` SET `value` =:value WHERE `key` = 'block'"); $query->bindParam(':value', json_encode($data), PDO::PARAM_STR); $query->execute(); } if (!empty($lastId)) { $j = 0; $tx_coun = count($info_block["tx"]); foreach ($info_block["tx"] as $value) { $encode_tx = $darkcoin->getrawtransaction("{$value}"); $tx_info = $darkcoin->decoderawtransaction($encode_tx); foreach ($tx_info["vout"] as $val) { $j += $val["value"]; } $query = $db->prepare("UPDATE `data` SET `txs` = :count, `tx_sum` = :sum WHERE `id` = :id"); $query->bindParam(':count', $tx_coun, PDO::PARAM_STR); $query->bindParam(':sum', $j, PDO::PARAM_STR); $query->bindParam(':id', $lastId, PDO::PARAM_STR); $query->execute(); } } }
function createStatistics($graph, $limit, $lastUpdate, $language) { SpotTranslation::initialize($language); $spotStatistics = new SpotStatistics($this->_db); include_once "images/pchart/pData.class.php"; include_once "images/pchart/pDraw.class.php"; include_once "images/pchart/pImage.class.php"; $width = 800; $height = 500; $titleHeight = 20; $dataSet = array(); $graphs = $this->getValidStatisticsGraphs(); $limits = $this->getValidStatisticsLimits(); switch ($graph) { case 'spotsperhour': $prepData = $this->prepareData($spotStatistics->getSpotCountPerHour($limit, $lastUpdate)); $legend = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'); for ($x = 0; $x <= 23; $x++) { $dataSet[] = @$prepData[$x]; } $graphicType = "bar"; break; case 'spotsperweekday': $prepData = $this->prepareData($spotStatistics->getSpotCountPerWeekday($limit, $lastUpdate)); $legend = array(_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday")); $dataSet = array(@$prepData[1], @$prepData[2], @$prepData[3], @$prepData[4], @$prepData[5], @$prepData[6], @$prepData[0]); $graphicType = "bar"; break; case 'spotspermonth': $prepData = $this->prepareData($spotStatistics->getSpotCountPerMonth($limit, $lastUpdate)); $legend = array(_("January"), _("February"), _("March"), _("April"), _("May"), _("June"), _("July"), _("August"), _("September"), _("October"), _("November"), _("December")); for ($x = 1; $x <= 12; $x++) { $dataSet[] = @$prepData[$x]; } $graphicType = "bar"; break; case 'spotspercategory': $prepData = $this->prepareData($spotStatistics->getSpotCountPerCategory($limit, $lastUpdate)); $legend = array(_(SpotCategories::HeadCat2Desc(0)), _(SpotCategories::HeadCat2Desc(1)), _(SpotCategories::HeadCat2Desc(2)), _(SpotCategories::HeadCat2Desc(3))); for ($x = 0; $x <= 3; $x++) { $dataSet[] = @$prepData[$x]; } $graphicType = "3Dpie"; break; } # switch array_walk($dataSet, create_function('& $item, $key', 'if ($item === NULL) $item = 0;')); $title = $graphs[$graph]; if (!empty($limit)) { $title .= " (" . $limits[$limit] . ")"; } # if $imgData = new pData(); if ($graphicType == "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 ($graphicType == "3Dpie") { include_once "images/pchart/pPie.class.php"; $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(); $data = $this->getImageInfoFromString($imageString); return array('metadata' => $data['metadata'], 'content' => $imageString); } # img }
<?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");
/* 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");
$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 3D 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)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $MyData); /* Define the slice color */ $PieChart->setSliceColor(0, array("R" => 143, "G" => 197, "B" => 0)); $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 */ $PieChart->draw3DPie(120, 125, array("SecondPass" => FALSE)); /* Draw an AA pie chart */ $PieChart->draw3DPie(340, 125, array("DrawLabels" => TRUE, "Border" => TRUE)); /* 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(560, 125, array("DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => TRUE)); /* 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(600, 8, array("Style" => LEGEND_NOBORDER, "Mode" => LEGEND_HORIZONTAL)); /* Render the picture (choose the best way) */
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"); }
$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");
if ($pieValue == 2) { $WriteValues = PIE_VALUE_PERCENTAGE; } // 显示总量 if ($pieSum == 1) { $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);
$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();
/** * 绘制图表并生成图片 * @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); }
/* 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)); /* Render the picture (choose the best way) */ $myPicture->autoOutput("img.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"; }
function draw_3dpie_chart($WIDTH, $HEIGHT, $DATA, $CONFIG, $LEGEND, $FONT, $PALETTE = 'default') { /* Include all the pChart 2.0 classes */ include '../lib/pchart2/class/pDraw.class'; include '../lib/pchart2/class/pImage.class'; include '../lib/pchart2/class/pData.class'; include '../lib/pchart2/class/pPie.class'; $COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE); /* Create your dataset object */ $myData = new pData(); /* Add data in your dataset */ if ($CONFIG['type'] == 'percent') { foreach ($DATA[0] as $value) { if ($value['percent'] != 0) { $POINTS[] = $value['percent']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, '%'); } else { foreach ($DATA[0] as $value) { if ($value['value'] != 0) { $POINTS[] = $value['value']; if ($LEGEND == 'key') { $LABELS[] = $value['key']; } if ($LEGEND == 'label') { $LABELS[] = $value['label']; } } } $myData->addPoints($POINTS, $CONFIG['title']); $myData->setAxisUnit(0, ''); } /* Labels definition */ /* $myData->addPoints($LABELS,'Legend'); $myData->setSerieDescription('Legend',''); $myData->setAbscissa('Legend'); */ /* Will replace the whole color scheme by the selected palette */ $myData->loadPalette('lib/pchart2/palettes/' . $PALETTE . '.color', TRUE); /* Create a pChart object and associate your dataset */ $myPicture = new pImage($WIDTH, $HEIGHT, $myData); /* Draw border around the chart */ $myPicture->drawRectangle(0, 0, $WIDTH - 1, $HEIGHT - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Draw chart background */ //$myPicture->drawFilledRectangle(0,0,$WIDTH,$HEIGHT,array("R"=>$COLORS[1]['R'],"G"=>$COLORS[1]['G'],"B"=>$COLORS[1]['B'],"Alpha"=>10)); /* Define the boundaries of the graph area */ //$myPicture->setGraphArea(20,20,$WIDTH-20,$HEIGHT-40); /* Choose a nice font */ switch ($FONT['type']) { case 'serif': $fontname = 'lib/pchart2/fonts/LiberationSerif-Regular.ttf'; break; case 'sans': $fontname = 'lib/pchart2/fonts/LiberationSans-Regular.ttf'; break; } $myPicture->setFontProperties(array('FontName' => $fontname, 'FontSize' => $FONT['size'])); /* Create label with survey name */ //$myPicture->drawText(20,$HEIGHT-30,$CONFIG['title'],array("DrawBox"=>true,"BoxRounded"=>true,"BoxR"=>$COLORS[1]['R'],"BoxG"=>$COLORS[1]['G'],"BoxB"=>$COLORS[1]['B'],"BoxAlpha"=>20,"Align"=>TEXT_ALIGN_MIDDLELEFT)); /* Create the pPie object */ $PieChart = new pPie($myPicture, $myData); /* Draw a simple pie chart */ $PIE_WIDTH = $WIDTH - 40; // 20px margin on left and right $PIE_HEIGHT = $HEIGHT - 60; // 20px margin on top and 40px on bottom (space for legend) if ($PIE_WIDTH >= $PIE_HEIGHT) { // Landscape orientation of the graph... $PieRadius = round($PIE_HEIGHT / 2); } else { // Portrait orientation of the graph... $PieRadius = round($PIE_WIDTH / 2); } $PieX = round($WIDTH / 2); $PieY = round($HEIGHT / 2); $PieChart->draw3DPie($PieX, $PieY, array("Radius" => $PieRadius, "SecondPass" => false, "DrawLabels" => false)); /* Build the PNG file and send it to the web browser */ $myPicture->Stroke(); }