Example #1
1
 /**
  * Based on Example24.php
  */
 public function testXYChart()
 {
     // Dataset definition
     $DataSet = new pData();
     // Compute the points
     for ($i = 0; $i <= 360; $i = $i + 10) {
         $DataSet->addPoint(cos($i * 3.14 / 180) * 80 + $i, "Serie1");
         $DataSet->addPoint(sin($i * 3.14 / 180) * 80 + $i, "Serie2");
     }
     $DataSet->setSeriesName("Trigonometric function", "Serie1");
     $DataSet->addSeries("Serie1");
     $DataSet->addSeries("Serie2");
     $DataSet->SetXAxisName("X Axis");
     $DataSet->SetYAxisName("Y Axis");
     // Initialise the graph
     $canvas = new TestCanvas();
     $Test = new pChart(300, 300, $canvas);
     $Test->drawBackgroundGradient(new Color(0), -100);
     // Prepare the graph area
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->setGraphArea(55, 30, 270, 230);
     $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(213, 217, 221));
     $Test->drawXYScale($DataSet, $scaleStyle, "Serie1", "Serie2", 45);
     $backgroundStyle = new BackgroundStyle(new Color(213, 217, 221), FALSE, new Color(30), -50);
     $Test->drawGraphBackground($backgroundStyle);
     $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 20));
     // Draw the chart
     $Test->setShadowProperties(2, 2, new Color(0), 60, 4);
     $Test->drawXYGraph($DataSet->GetData(), "Serie1", "Serie2", 0);
     $Test->clearShadow();
     // Draw the title
     $Title = "Drawing X versus Y charts trigonometric functions  ";
     $Test->drawTextBox(new Point(0, 280), new Point(300, 300), $Title, 0, new Color(255), ALIGN_RIGHT, ShadowProperties::FromSettings(1, 1, new Color(0), 100, 0), new Color(0), 30);
     // Draw the legend
     $Test->setFontProperties("Fonts/pf_arma_five.ttf", 6);
     $DataSet->removeSeries("Serie2");
     $Test->drawLegend(160, 5, $DataSet->GetDataDescription(), new Color(0), new Color(0), new Color(255), FALSE);
     file_put_contents(dirname(__FILE__) . '/action_logs/testXYChart', $canvas->getActionLog());
     $this->assertEquals('3c45517b3d9549198ffffaac276ad353', md5($canvas->getActionLog()));
 }
Example #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");
 /**
  * Instantiate a new ShadowProperties with the same settings as
  * the one passed in. Essentially this is a clone method.
  *
  * @todo clone appears to be a reserved word in PHP, is there
  * actually any special clone functionality? I can't RTFM at the
  * moment as the internet connection is down.
  */
 public static function Copy(ShadowProperties $other)
 {
     $copy = ShadowProperties::FromSettings($other->xDistance, $other->yDistance, $other->color, $other->alpha, $other->blur);
     $copy->active = $other->active;
     return $copy;
 }
 /**
  * Set the shadow properties
  */
 function setShadowProperties($XDistance = 1, $YDistance = 1, Color $color = null, $Alpha = 50, $Blur = 0)
 {
     if ($color == null) {
         $color = new Color(60, 60, 60);
     }
     $this->shadowProperties = ShadowProperties::FromSettings($XDistance, $YDistance, $color, $Alpha, $Blur);
 }