Пример #1
0
require_once '../lib/GDCanvas.php';
require_once '../lib/BackgroundStyle.php';
// Definitions
$DataSet = new pData();
$canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $canvas);
// Dataset definition
CSVImporter::ImportFromCSV($DataSet, "../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
$DataSet->AddAllSeries();
$DataSet->setAbscissaLabelSeries();
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(60, 30, 680, 200);
$canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$canvas->drawRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$Chart->drawGraphBackground(new BackgroundStyle(new Color(255), TRUE));
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
$Chart->drawGrid(new GridStyle(4, TRUE, new Color(230, 230, 230), TRUE));
// Draw the 0 line
$Chart->setFontProperties("../Fonts/tahoma.ttf", 6);
$Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
// Draw the area
$Chart->drawArea($DataSet, "Serie 1", "Serie 3", new Color(239, 238, 227));
// Draw the line graph
$Chart->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
$Chart->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255));
// Finish the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(250));
$Chart->setFontProperties("../Fonts/tahoma.ttf", 10);
$Chart->drawTitle(60, 22, "Example 4", new Color(50), 585);
Пример #2
0
 public function testDrawArea()
 {
     // Dataset definition
     $DataSet = new pData();
     $DataSet->addPoints(array(10, 9.4, 7.7, 5, 1.7, -1.7, -5, -7.7, -9.4, -10, -9.4, -7.7, -5, -1.8, 1.7), "Serie1");
     $DataSet->addPoints(array(0, 3.4, 6.4, 8.699999999999999, 9.800000000000001, 9.800000000000001, 8.699999999999999, 6.4, 3.4, 0, -3.4, -6.4, -8.6, -9.800000000000001, -9.9), "Serie2");
     $DataSet->addPoints(array(7.1, 9.1, 10, 9.699999999999999, 8.199999999999999, 5.7, 2.6, -0.9, -4.2, -7.1, -9.1, -10, -9.699999999999999, -8.199999999999999, -5.8), "Serie3");
     $DataSet->addPoints(array("Jan", "Jan", "Jan", "Feb", "Feb", "Feb", "Mar", "Mar", "Mar", "Apr", "Apr", "Apr", "May", "May", "May"), "Serie4");
     $DataSet->AddAllSeries();
     $DataSet->SetAbscissaLabelSeries("Serie4");
     $DataSet->SetSeriesName("Max Average", "Serie1");
     $DataSet->SetSeriesName("Min Average", "Serie2");
     $DataSet->SetSeriesName("Temperature", "Serie3");
     $DataSet->SetYAxisName("Temperature");
     $DataSet->SetXAxisName("Month of the year");
     // Initialise the graph
     $canvas = new TestCanvas();
     $Test = new pChart(700, 230, $canvas);
     $Test->reportWarnings("GD");
     $Test->setFixedScale(-12, 12, 5);
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->setGraphArea(65, 30, 570, 185);
     $canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
     $backgroundStyle = new BackgroundStyle(new Color(255), TRUE);
     $Test->drawGraphBackground($backgroundStyle);
     $scaleStyle = new ScaleStyle(SCALE_NORMAL, new Color(150));
     $Test->drawScale($DataSet, $scaleStyle, 0, 2, TRUE, 3);
     $Test->drawGrid(new GridStyle(4, TRUE, new Color(230), 50));
     // Draw the 0 line
     $Test->setFontProperties("Fonts/tahoma.ttf", 6);
     $Test->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
     // Draw the area
     $DataSet->RemoveSeries("Serie4");
     $Test->drawArea($DataSet->GetData(), "Serie1", "Serie2", new Color(239, 238, 227), 50);
     $DataSet->RemoveSeries("Serie3");
     $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     // Draw the line graph
     $Test->setLineStyle(1, 6);
     $DataSet->RemoveAllSeries();
     $DataSet->AddSeries("Serie3");
     $Test->drawLineGraph($DataSet->GetData(), $DataSet->GetDataDescription());
     $Test->drawPlotGraph($DataSet->GetData(), $DataSet->GetDataDescription(), 3, 2, new Color(255));
     // Write values on Serie3
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->writeValues($DataSet->GetData(), $DataSet->GetDataDescription(), "Serie3");
     // Finish the graph
     $Test->setFontProperties("Fonts/tahoma.ttf", 8);
     $Test->drawLegend(590, 90, $DataSet->GetDataDescription(), new Color(255));
     $Test->setFontProperties("Fonts/tahoma.ttf", 10);
     $Test->drawTitle(60, 22, "example 15", new Color(50), 585);
     // Add an image
     $Test->drawFromPNG(dirname(__FILE__) . "/../Sample/logo.png", 584, 35);
     $this->assertEquals('53b34d556af518230b7556e19349bd94', md5($canvas->getActionLog()));
 }
Пример #3
0
require_once '../lib/BackgroundStyle.php';
// Definitions
$DataSet = new pData();
$Canvas = new GDCanvas(700, 230);
$Chart = new pChart(700, 230, $Canvas);
// Dataset
CSVImporter::importFromCSV($DataSet, dirname(__FILE__) . "/../sample/datawithtitle.csv", ",", array(1, 2, 3), TRUE, 0);
$DataSet->AddAllSeries();
$DataSet->SetAbscissaLabelSeries();
// Initialise the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->setGraphArea(60, 30, 680, 200);
$Canvas->drawFilledRoundedRectangle(new Point(7, 7), new Point(693, 223), 5, new Color(240), 1, 0, ShadowProperties::NoShadow());
$Canvas->drawFilledRoundedRectangle(new Point(5, 5), new Point(695, 225), 5, new Color(230), 1, 0, ShadowProperties::NoShadow());
$backgroundStyle = new BackgroundStyle(new Color(255), TRUE);
$Chart->drawGraphBackground($backgroundStyle);
$Chart->drawScale($DataSet, ScaleStyle::DefaultStyle(), 0, 2);
$Chart->drawGrid(new GridStyle(4, TRUE, new Color(230), 50));
// Draw the 0 line
$Chart->setFontProperties("../Fonts/tahoma.ttf", 6);
$Chart->drawTreshold(0, new Color(143, 55, 72), TRUE, TRUE);
// Draw the filled line graph
$Chart->drawFilledLineGraph($DataSet->getData(), $DataSet->getDataDescription(), 50, True);
// Finish the graph
$Chart->setFontProperties("../Fonts/tahoma.ttf", 8);
$Chart->drawLegend(65, 35, $DataSet->GetDataDescription(), new Color(255));
$Chart->setFontProperties("../Fonts/tahoma.ttf", 10);
$Chart->drawTitle(60, 22, "Example 6", new Color(50), 585);
$Chart->Render("Example6.png");
header("Content-Type:image/png");
echo file_get_contents("Example6.png");