Example #1
0
function create_common_image($title, $width, $height, $data, $chart_type = 'line')
{
    global $pchart_path;
    /* Create the pChart object */
    $myPicture = new pImage($width, $height, $data);
    /* Draw the background */
    $Settings = array("R" => 255, "G" => 255, "B" => 255, "Dash" => 1, "DashR" => 185, "DashG" => 225, "DashB" => 255);
    $myPicture->drawFilledRectangle(0, 0, $width, $height, $Settings);
    /* Overlay with a gradient */
    $Settings = array("StartR" => 206, "StartG" => 235, "StartB" => 235, "EndR" => 71, "EndG" => 150, "EndB" => 205, "Alpha" => 50);
    $myPicture->drawGradientArea(0, 0, $width, $height, DIRECTION_VERTICAL, $Settings);
    $myPicture->drawGradientArea(0, 0, $width, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80));
    /* Add a border to the picture */
    $myPicture->drawRectangle(0, 0, $width - 1, $height - 1, array("R" => 0, "G" => 0, "B" => 0));
    /* Write the picture title */
    $myPicture->setFontProperties(array("FontName" => $pchart_path . "/fonts/arialbd.ttf", "FontSize" => 9));
    $myPicture->drawText(24, 12, win2uni($title), array("R" => 255, "G" => 255, "B" => 255, "Align" => TEXT_ALIGN_MIDDLELEFT));
    $myPicture->drawFromPNG(4, 4, "includes/design/images/chart_pie.png");
    if ($chart_type == 'line') {
        $myPicture->setFontProperties(array("FontName" => $pchart_path . "/fonts/arial.ttf", "FontSize" => 8));
        /* Draw the scale and the 1st chart */
        $myPicture->setGraphArea(60, 64, 450 + 200, 190);
        $myPicture->drawFilledRectangle(60, 50, 450 + 200, 190, array("R" => 255, "G" => 255, "B" => 255, "Surrounding" => -255, "Alpha" => 60));
        $myPicture->drawScale(array("Mode" => SCALE_MODE_START0, "DrawSubTicks" => FALSE, "GridR" => 151, "GridG" => 197, "GridB" => 254, "GridAlpha" => 30));
        $myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10));
    }
    $myPicture->setFontProperties(array("FontName" => $pchart_path . "/fonts/pf_arma_five.ttf", "FontSize" => 6));
    return $myPicture;
}
function pch_vertical_graph($graph_type, $index, $data, $width, $height, $rgb_color = false, $xaxisname = "", $yaxisname = "", $show_values = false, $legend = array(), $font, $antialiasing, $water_mark = '', $font_size)
{
    /* CAT:Vertical Charts */
    if (!is_array($legend) || empty($legend)) {
        unset($legend);
    }
    /*$legend=array('pep1' => 'pep1','pep2' => 'pep2','pep3' => 'pep3','pep4' => 'pep4');
    	 $data=array(array('pep1' => 1, 'pep2' => 1, 'pep3' => 3, 'pep4' => 3), array('pep1' => 1, 'pep2' => 3, 'pep3' => 1,'pep4' => 4), array('pep1' => 3, 'pep2' => 1, 'pep3' => 1,'pep4' =>1), array('pep1' => 1, 'pep2' =>1, 'pep3' =>1,'pep4' =>0));
    	 $index=array(1,2,3,4);
         */
    if (is_array(reset($data))) {
        $data2 = array();
        foreach ($data as $i => $values) {
            $c = 0;
            foreach ($values as $i2 => $value) {
                $data2[$i2][$i] = $value;
                $c++;
            }
        }
        $data = $data2;
    } else {
        $data = array($data);
    }
    /* Create and populate the pData object */
    $MyData = new pData();
    foreach ($data as $i => $values) {
        if (isset($legend)) {
            $point_id = $legend[$i];
        } else {
            $point_id = $i;
        }
        $MyData->addPoints($values, $point_id);
        if (!empty($rgb_color)) {
            $MyData->setPalette($point_id, array("R" => $rgb_color[$i]['color']["R"], "G" => $rgb_color[$i]['color']["G"], "B" => $rgb_color[$i]['color']["B"], "BorderR" => $rgb_color[$i]['border']["R"], "BorderG" => $rgb_color[$i]['border']["G"], "BorderB" => $rgb_color[$i]['border']["B"], "Alpha" => $rgb_color[$i]['alpha']));
            /*$palette_color = array();
            			if (isset($rgb_color[$i]['color'])) {
            				$palette_color["R"] = $rgb_color[$i]['color']["R"];
            				$palette_color["G"] = $rgb_color[$i]['color']["G"];
            				$palette_color["B"] = $rgb_color[$i]['color']["B"];
            			}
            	 		if (isset($rgb_color[$i]['color'])) {
            				$palette_color["BorderR"] = $rgb_color[$i]['border']["R"];
            				$palette_color["BorderG"] = $rgb_color[$i]['border']["G"];
            				$palette_color["BorderB"] = $rgb_color[$i]['border']["B"];
            			}
            			if (isset($rgb_color[$i]['color'])) {
            				$palette_color["Alpha"] = $rgb_color[$i]['Alpha'];
            			}
            		
            			$MyData->setPalette($point_id, $palette_color);*/
        }
        $MyData->setSerieWeight($point_id, 1);
    }
    //$MyData->addPoints($data,"Yaxis");
    $MyData->setAxisName(0, $yaxisname);
    $MyData->addPoints($index, "Xaxis");
    $MyData->setSerieDescription("Xaxis", $xaxisname);
    $MyData->setAbscissa("Xaxis");
    /* Create the pChart object */
    $myPicture = new pImage($width, $height, $MyData);
    /* Turn of Antialiasing */
    $myPicture->Antialias = $antialiasing;
    /* Add a border to the picture */
    //$myPicture->drawRectangle(0,0,$width,$height,array("R"=>0,"G"=>0,"B"=>0));
    /* Set the default font */
    $myPicture->setFontProperties(array("FontName" => $font, "FontSize" => $font_size));
    if (isset($legend)) {
        /* Set horizontal legend if is posible */
        $legend_mode = LEGEND_HORIZONTAL;
        $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode));
        if ($size['Width'] > $width - 5) {
            $legend_mode = LEGEND_VERTICAL;
            $size = $myPicture->getLegendSize(array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode));
        }
        /* Write the chart legend */
        $myPicture->drawLegend($width - $size['Width'], 8, array("Style" => LEGEND_NOBORDER, "Mode" => $legend_mode));
    }
    //Calculate the bottom margin from the size of string in each index
    $max_chars = 0;
    foreach ($index as $string_index) {
        if (empty($string_index)) {
            continue;
        }
        $len = strlen($string_index);
        if ($len > $max_chars) {
            $max_chars = $len;
        }
    }
    $margin_bottom = 10 * $max_chars;
    $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 - $margin_bottom, $water_mark);
    }
    if (isset($size['Height'])) {
        /* Define the chart area */
        $myPicture->setGraphArea(40, $size['Height'], $width - $water_mark_width, $height - $margin_bottom);
    } else {
        /* Define the chart area */
        $myPicture->setGraphArea(40, 5, $width - $water_mark_width, $height - $margin_bottom);
    }
    /* Draw the scale */
    $scaleSettings = array("GridR" => 200, "GridG" => 200, "GridB" => 200, "DrawSubTicks" => TRUE, "CycleBackground" => TRUE, "Mode" => SCALE_MODE_START0, "LabelRotation" => 60, "XMargin" => 0);
    $myPicture->drawScale($scaleSettings);
    /* Turn on shadow computing */
    //$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
    switch ($graph_type) {
        case 'stacked_area':
            $ForceTransparency = "-1";
            break;
        default:
            $ForceTransparency = "50";
            break;
    }
    /* Draw the chart */
    $settings = array("ForceTransparency" => $ForceTransparency, "Gradient" => TRUE, "GradientMode" => GRADIENT_EFFECT_CAN, "DisplayValues" => $show_values, "DisplayZeroValues" => FALSE, "DisplayR" => 100, "DisplayZeros" => FALSE, "DisplayG" => 100, "DisplayB" => 100, "DisplayShadow" => TRUE, "Surrounding" => 5, "AroundZero" => FALSE);
    switch ($graph_type) {
        case "stacked_area":
        case "area":
            $myPicture->drawAreaChart($settings);
            break;
        case "line":
            $myPicture->drawLineChart($settings);
            break;
    }
    /* Render the picture */
    $myPicture->stroke();
}
/* Define default font settings */
$myPicture->setFontProperties(array("FontName" => "../fonts/Forgotte.ttf", "FontSize" => 14));
/* Create the background */
$myPicture->drawGradientArea(0, 0, 500, 230, DIRECTION_HORIZONTAL, array("StartR" => 217, "StartG" => 250, "StartB" => 116, "EndR" => 181, "EndG" => 209, "EndB" => 27, "Alpha" => 100));
$RectangleSettings = array("R" => 181, "G" => 209, "B" => 27, "Alpha" => 100);
$myPicture->drawFilledRectangle(500, 0, 700, 230, $RectangleSettings);
/* Enable shadow computing on a (+1,+1) basis */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20));
/* Draw the left area */
$RectangleSettings = array("R" => 181, "G" => 209, "B" => 27, "Alpha" => 100);
$myPicture->drawRoundedFilledRectangle(-5, 0, 20, 240, 10, $RectangleSettings);
$TextSettings = array("R" => 255, "G" => 255, "B" => 255, "Angle" => 90, "Align" => TEXT_ALIGN_MIDDLELEFT);
$myPicture->drawText(10, 220, "My first chart", $TextSettings);
/* Draw the right area */
$RectangleSettings = array("R" => 191, "G" => 219, "B" => 37, "Alpha" => 100, "Surrounding" => 20, "Ticks" => 2);
$myPicture->drawFilledRectangle(510, 10, 689, 219, $RectangleSettings);
/* Write the legend */
$TextSettings = array("R" => 255, "G" => 255, "B" => 255, "Align" => TEXT_ALIGN_MIDDLEMIDDLE);
$myPicture->drawText(600, 30, "Weather data", $TextSettings);
$TextSettings = array("R" => 106, "G" => 125, "B" => 3, "Align" => TEXT_ALIGN_TOPLEFT, "FontSize" => 11);
$myPicture->drawText(520, 45, "The   data  shown  here   has   been", $TextSettings);
$myPicture->drawText(520, 60, "collected from European locations", $TextSettings);
$myPicture->drawText(520, 75, "by the French NAVI system.", $TextSettings);
$myPicture->drawFromPNG(540, 90, "resources/blocnote.png");
/* Disable shadow computing  */
$myPicture->setShadow(FALSE);
/* Draw the picture border */
$RectangleSettings = array("R" => 181, "G" => 209, "B" => 27, "Alpha" => 100);
$myPicture->drawRectangle(0, 0, 699, 229, $RectangleSettings);
/* Render the picture (choose the best way) */
$myPicture->autoOutput("pictures/example.drawingObjects.png");
include "../class/pDraw.class.php";
include "../class/pImage.class.php";
/* Create the pChart object */
$myPicture = new pImage(700, 230);
/* Draw the background */
$Settings = array("R" => 170, "G" => 183, "B" => 87, "Dash" => 1, "DashR" => 190, "DashG" => 203, "DashB" => 107);
$myPicture->drawFilledRectangle(0, 0, 700, 230, $Settings);
/* Overlay with a gradient */
$Settings = array("StartR" => 219, "StartG" => 231, "StartB" => 139, "EndR" => 1, "EndG" => 138, "EndB" => 68, "Alpha" => 50);
$myPicture->drawGradientArea(0, 0, 700, 230, DIRECTION_VERTICAL, $Settings);
$myPicture->drawGradientArea(0, 0, 700, 20, DIRECTION_VERTICAL, array("StartR" => 0, "StartG" => 0, "StartB" => 0, "EndR" => 50, "EndG" => 50, "EndB" => 50, "Alpha" => 80));
/* Add a border to the picture */
$myPicture->drawRectangle(0, 0, 699, 229, array("R" => 0, "G" => 0, "B" => 0));
/* Write the picture title */
$myPicture->setFontProperties(array("FontName" => "../fonts/Silkscreen.ttf", "FontSize" => 6));
$myPicture->drawText(10, 13, "drawFromPNG() - add pictures to your charts", array("R" => 255, "G" => 255, "B" => 255));
/* Turn off shadow computing */
$myPicture->setShadow(FALSE);
/* Draw a PNG object */
$myPicture->drawFromPNG(180, 50, "resources/hologram.png");
/* Turn on shadow computing */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20));
/* Draw a PNG object */
$myPicture->drawFromPNG(400, 50, "resources/blocnote.png");
/* Write the legend */
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 20));
$TextSettings = array("R" => 255, "G" => 255, "B" => 255, "FontSize" => 10, "FontName" => "../fonts/calibri.ttf", "Align" => TEXT_ALIGN_BOTTOMMIDDLE);
$myPicture->drawText(240, 190, "          Without shadow\r\n(only PNG alpha channels)", $TextSettings);
$myPicture->drawText(460, 200, "With enhanced shadow", $TextSettings);
/* Render the picture (choose the best way) */
$myPicture->autoOutput("pictures/example.drawFromPNG.png");