/**
  * Create a PieChart
  *
  * @param array $data associative array contianing label and values
  */
 protected function PieChart($data)
 {
     $DataSet = new pData();
     $Canvas = new GDCanvas(400, 200, false);
     $Chart = new PieChart(400, 200, $Canvas);
     $Chart->setFontProperties(dirname(__FILE__) . '/pchart/Fonts/DroidSans.ttf', 8);
     $DataSet->AddPoints(array_values($data), 'Serie1');
     $DataSet->AddPoints(array_keys($data), 'Serie2');
     $DataSet->AddAllSeries();
     $DataSet->SetAbscissaLabelSeries("Serie2");
     $Chart->drawBasicPieGraph($DataSet->getData(), $DataSet->GetDataDescription(), 120, 100, 60, PIE_PERCENTAGE);
     $Chart->drawPieLegend(230, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), new Color(250));
     header('Content-Type: image/png');
     $Chart->Render('');
 }
示例#2
0
<?php

/*
    Example13: A 2D exploded pie graph
*/
// Standard inclusions
require_once "../lib/pData.php";
require_once "../lib/pChart.php";
require_once '../lib/GDCanvas.php';
require_once '../lib/BackgroundStyle.php';
require_once '../lib/PieChart.php';
// Definitions
$DataSet = new pData();
$Canvas = new GDCanvas(300, 200);
$Chart = new PieChart(300, 200, $Canvas);
// Dataset
$DataSet->AddPoints(array(10, 2, 3, 5, 3), "Serie1");
$DataSet->AddPoints(array("Jan", "Feb", "Mar", "Apr", "May"), "Serie2");
$DataSet->AddAllSeries();
$DataSet->SetAbscissaLabelSeries("Serie2");
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
// Draw the pie chart
$shadowProperties = ShadowProperties::FromSettings(2, 2, new Color(200));
$Chart->drawFlatPieGraphWithShadow($DataSet->GetData(), $DataSet->GetDataDescription(), 120, 100, 60, PIE_PERCENTAGE, 8, 0, $shadowProperties);
$Chart->drawPieLegend(230, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), new Color(250));
$Chart->Render("Example13.png");
header("Content-Type:image/png");
readfile("Example13.png");
示例#3
0
 public function testDrawBasicPieGraph()
 {
     // Dataset definition
     $DataSet = new pData();
     $DataSet->addPoints(array(10, 2, 3, 5, 3), "Serie1");
     $DataSet->addPoints(array("Jan", "Feb", "Mar", "Apr", "May"), "Serie2");
     $DataSet->AddAllSeries();
     $DataSet->setAbscissaLabelSeries("Serie2");
     $this->assertEquals(array(0 => array('Serie1' => 10, 'Name' => 0, 'Serie2' => 'Jan'), 1 => array('Serie1' => 2, 'Name' => 1, 'Serie2' => 'Feb'), 2 => array('Serie1' => 3, 'Name' => 2, 'Serie2' => 'Mar'), 3 => array('Serie1' => 5, 'Name' => 3, 'Serie2' => 'Apr'), 4 => array('Serie1' => 3, 'Name' => 4, 'Serie2' => 'May')), $DataSet->getData());
     $this->assertEquals(array(0 => 'Serie1', 1 => 'Serie2'), $DataSet->getDataDescription()->values);
     // Initialise the graph
     $canvas = new TestCanvas();
     $Test = new PieChart(300, 200, $canvas);
     $Test->loadColorPalette(dirname(__FILE__) . "/../sample/softtones.txt");
     // Draw the pie chart
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->drawBasicPieGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 120, 100, ShadowProperties::NoShadow(), 70, PIE_PERCENTAGE, new Color(255, 255, 218));
     $Test->drawPieLegend(230, 15, $DataSet->GetData(), $DataSet->GetDataDescription(), new Color(250));
     $this->assertEquals('0ec1d5de67ae53239101143106d5ee4a', md5($canvas->getActionLog()));
 }