示例#1
0
 function renderChart($chartType, $title, $prepData, $legend)
 {
     $width = 800;
     $height = 500;
     $titleHeight = 20;
     /*
      * Create a dataset we can use
      */
     $dataSet = array_values($prepData);
     $imgData = new pData();
     if ($chartType == "bar") {
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $imgData->setPalette("data", array("R" => 0, "G" => 108, "B" => 171, "Alpha" => 100));
         $img = new pImage($width, $height, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $img->setFontProperties(array("R" => 255, "G" => 255, "B" => 255, "FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $img->setGraphArea(60, $titleHeight + 20, $width - 50, $height - 30);
         $img->drawScale(array("GridR" => 200, "GridG" => 200, "GridB" => 200, "Mode" => SCALE_MODE_START0));
         $img->drawBarChart(array("Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayPos" => LABEL_POS_INSIDE, "DisplayValues" => TRUE, "Surrounding" => 10));
     } elseif ($chartType == "3Dpie") {
         $imgData->addPoints($dataSet, "data");
         $imgData->addPoints($legend, "legend");
         $imgData->setAbscissa("legend");
         $img = new pImage($width, $height, $imgData, TRUE);
         $PieChart = new pPie($img, $imgData);
         $img->drawGradientArea(0, $titleHeight, $width, $height, DIRECTION_VERTICAL, array("StartR" => 200, "StartG" => 200, "StartB" => 200, "EndR" => 18, "EndG" => 52, "EndB" => 86, "Alpha" => 100));
         $img->drawGradientArea(0, 0, $width, $titleHeight, DIRECTION_VERTICAL, array("StartR" => 18, "StartG" => 52, "StartB" => 86, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Bold.ttf", "FontSize" => 10));
         $img->drawText($width / 2, 13, $title, array("Align" => TEXT_ALIGN_MIDDLEMIDDLE, "R" => 255, "G" => 255, "B" => 255));
         $PieChart->setSliceColor(0, array("R" => 0, "G" => 108, "B" => 171));
         $PieChart->setSliceColor(1, array("R" => 205, "G" => 159, "B" => 0));
         $PieChart->setSliceColor(2, array("R" => 0, "G" => 171, "B" => 0));
         $PieChart->setSliceColor(3, array("R" => 171, "G" => 28, "B" => 0));
         $img->setFontProperties(array("FontName" => "images/ttf/liberation-sans/LiberationSans-Regular.ttf", "FontSize" => 9));
         $PieChart->draw3DPie($width / 2, $height / 2 + $titleHeight, array("Radius" => $width / 2 - 100, "SecondPass" => TRUE, "DrawLabels" => TRUE, "WriteValues" => TRUE, "Precision" => 2, "ValueR" => 0, "ValueG" => 0, "ValueB" => 0, "ValueAlpha" => 100, "SkewFactor" => 0.6, "LabelR" => 255, "LabelG" => 255, "LabelB" => 255, "LabelAlpha" => 100));
     }
     # if
     if (isset($img)) {
         ob_start();
         $img->render(NULL);
         $imageString = ob_get_clean();
         $dimensions = $this->_svcImageUtil->getImageDimensions($imageString);
         return array('metadata' => $dimensions, 'content' => $imageString);
     } else {
         return false;
     }
     # else
 }
function 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";
}
示例#3
0
             $arrPieValues[] = $arrCols[$field][$rowPie];
         }
     }
 }
 $myData->addPoints($arrPieLabels, 'pieLabel');
 $myData->addPoints($arrPieValues, $pieValueKey);
 $abscissa = 'pieLabel';
 $myData->setAbscissa($abscissa);
 /* Create the pPie object */
 $PieChart = new pPie($myPicture, $myData);
 $myPicture->setFontProperties(array("FontName" => "./fonts/msyh.ttf", "FontSize" => $font, "R" => 0, "G" => 0, "B" => 0));
 /* Define the slice color */
 // 若设置了色板,配入饼图
 if (isset($palette)) {
     for ($slice = 0; $slice < count($arrPieLabels); $slice++) {
         $PieChart->setSliceColor($slice, $palette['serie'][$slice % $palette['serie_num']]);
     }
 }
 /* Draw Pie */
 // 设置数值显示类型,1:显示数值,2:显示比例,否则不显示;
 $WriteValues = NULL;
 if ($pieValue == 1) {
     $WriteValues = PIE_VALUE_NATURAL;
 }
 if ($pieValue == 2) {
     $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));
 }
 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;
 }
示例#5
0
 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));
 }
示例#6
0
/* 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");
示例#7
0
$myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings);
/* Draw a gradient overlay */
$Settings = array("StartR" => 209, "StartG" => 150, "StartB" => 231, "EndR" => 111, "EndG" => 3, "EndB" => 138, "Alpha" => 50);
$myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings);
$myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 100));
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6));
$myPicture->drawText(10, 13, "pPie - Draw 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));
示例#8
0
 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
 }
示例#9
0
文件: Graph.php 项目: Krinkle/xtools
 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 . " &middot; {$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;
 }
示例#10
0
 public static function drawchart($data)
 {
     // Include the chart libraries.
     $plib = '../iomad/pchart';
     require_once "{$plib}/class/pDraw.class.php";
     require_once "{$plib}/class/pPie.class.php";
     require_once "{$plib}/class/pImage.class.php";
     require_once "{$plib}/class/pData.class.php";
     // Chart data.
     $chartdata = new pData();
     $chartdata->addPoints(array($data->notstarted, $data->inprogress, $data->completed), "Value");
     // Labels.
     $chartdata->addPoints(array('Not started', 'In progress', 'Completed'), "Legend");
     $chartdata->setAbscissa("Legend");
     // Chart object.
     $chart = new pImage(350, 180, $chartdata);
     // Pie chart object.
     $pie = new pPie($chart, $chartdata);
     $chart->setShadow(false);
     $chart->setFontProperties(array("FontName" => "{$plib}/fonts/GeosansLight.ttf", "FontSize" => 11));
     $pie->setSliceColor(0, array("R" => 200, "G" => 0, "B" => 0));
     $pie->setSliceColor(1, array("R" => 200, "G" => 200, "B" => 0));
     $pie->setSliceColor(2, array("R" => 0, "G" => 200, "B" => 0));
     $pie->draw3Dpie(175, 100, array("Radius" => 80, "DrawLabels" => true, "DataGapAngle" => 10, "DataGapRadius" => 6, "Border" => true));
     // Display the chart.
     $chart->stroke();
 }