Exemple #1
0
$WIDTH = param_integer('width', 400);
$HEIGHT = param_integer('height', 250);
$PALETTE = param_alpha('palette', 'default');
$FONT['type'] = param_alpha('fonttype', 'sans');
// possible values are 'sans' and 'serif'
$FONT['size'] = param_integer('fontsize', 10);
$OWNER = param_integer('id');
$DATA = PluginBlocktypeCompetencesKadis::prepare_chart_data($OWNER);
//log_debug($DATA);
$CONFIG = PluginBlocktypeCompetencesKadis::prepare_chart_config();
/* Include all the pChart 2.0 classes */
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pDraw.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pImage.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pData.class';
include dirname(dirname(dirname(__FILE__))) . '/lib/pchart2/class/pRadar.class';
$COLORS = ArtefactTypeSurvey::get_palette_colors($PALETTE);
/* Create your dataset object */
$myData = new pData();
/* Add data in your dataset */
$POINTS = array();
$LABELS = array();
foreach ($DATA as $value) {
    $POINTS[] = $value['value'];
    $LABELS[] = $value['key'];
}
$myData->addPoints($POINTS, $CONFIG['title']);
$myData->setAxisUnit(0, '');
/* Labels definition */
$myData->addPoints($LABELS, 'Legend');
$myData->setSerieDescription('Legend', '');
$myData->setAbscissa('Legend');
Exemple #2
0
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();
}