GraPHPiteOpen Source PHP OO Graph Rendering Utility
Differences using GraPHPite with GD1 and GD2

Below you can see how GD 2's extended functionality versus GD 1 makes the GraPHPite objects look considerably better.

The example show below is an absolute worst-case-scenario example. It makes heavy use of the extra functionality in GD 2. This should not be seen as "GraPHPite does not work when using GD 1", because GraPHPite does work on GD 1 but there are some limitations.

The below script using GD1
GD 1.x Sample

The below script using GD2
GD 2.x Sample

The differences between GD1 and GD2 using GraPHPite are:

  • TrueColor images not supported (no real problem here)
  • Alpha blending not supported, ie. (semi)-transparent effects
  • Resizing of images is not resampled, but purely pixelated, this means that you should not use the Thumbnail functionality
  • Circles not supported, ie. CircleMarker
  • Setting of line thickness

ALL (well, not CircleMarker :p), of these are used in the above example, hence the huge difference. Below is an example of a GraPHP created using GD1 and GD2 where only a small bit of alpha blendng were used (to demonstrate that there IS a difference), and they are almost identical.

A sample using GD1
GD 1.x Sample

The same sample using GD2
GD 2.x Sample

<?php 

include ("../include/graphpite/graphpite.inc");

// create the graph
$Graph = & new GraPHP(800600);
// create the plotarea
$Graph->add(new PlotArea(), "PlotArea");

// create some colors
$Graph->addColor(new Color(25500), "Red");
$Graph->addColor(new Color(2552550), "Yellow");
$Graph->addColor(new Color(000), "Black");
$Graph->addColor(new Color(255255255), "White");
$Graph->addColor(new Color(0xee0xee0xee), "LightGray");
$Graph->addColor(new Color(00127), "Blue");
$Graph->addColor(new Color(101010), "Transparent");

// set the blue color to almost transparent, requires GD2
$Blue->setAlpha(100);

// set the transparent to TRANSPARENT, requires GD2
$Transparent->setAlpha(255);

// create a Y grid
$PlotArea->addGridY(new GridBars(), "GridY");
// that is light gray in color
$GridY->setFillStyle($LightGray);

// create the 1st dataset
$DataSet1 = & new RandomDataSet(1020100true);
// create the 1st plot as smoothed area chart using the 1st dataset
$PlotArea->addPlot(new SmoothedAreaChart($DataSet1), "Plot1");
// create a vertical gradient fill using red and yellow, ie bottom of graph 
// will be yellow and the "higher" the value the more red it will be, ie a "fire" effect
$Plot1->setFillStyle(new GradientFill(GRAD_VERTICAL$Red$Yellow100));

// create a Y data value marker
$Plot1->add(new ValueMarker(PCT_Y_MAX), "Marker");
// fill it with white
$Marker->setFillStyle($White);
// and use black border
$Marker->setBorderStyle($Black);
// create a pin-point marker type
$Plot1->add(new AngularPointingMarker(20$Marker), "PointingMarker");
// and use the marker on the 1st plot
$Plot1->setMarker($PointingMarker);
// format value marker labels as percentage values
$Marker->setDataPreProcessor(new FormattedData("%0.1f%%"));

// create the 2nd dataset
$DataSet2 = & new RandomDataSet(1020100true);
// create the 2nd plot as line chart using the 2nd dataset
$PlotArea->addPlot(new LineChart($DataSet2), "Plot2");
// create a dashed line style
$Graph->add(new DashedLine($Black$Transparent), "LineStyle");
// set the linecharts line style to the dashed style
$Plot2->setLineStyle($LineStyle);
// Create a cross marker
$Plot2->setMarker(new CrossMarker(), "Marker");
// Create a red line
$LineStyle = & new SolidLine($Red);
// which is bold
$LineStyle->setThickness(5);
// and make the marker use this line style
$Marker->setLineStyle($LineStyle);

// create a 3rd dataset
$DataSet3 = & new RandomDataSet(810120false);
// create the 3rd plot as line chart using the 2nd dataset
$PlotArea->addPlot(new BarChart($DataSet3), "Plot3");
// set the fill style of the barchart to the almost transparent blue
$Plot3->setFillStyle($Blue);

// add a TrueType font
$Graph->addFont(new FontTTF("c:\windows\fonts\arial.ttf"), "Arial");
// set the font size to 15 pixels
$Arial->setSize(15);
// add a title using the created font
$Graph->add(new Title("GraPHPite - Sample"$Arial));

// Show arrow heads on the axis
$PlotArea->AxisX->showArrow();
$PlotArea->AxisY->showArrow();

// create an data label array for formatting label data based on an array
$ArrayData = & new ArrayData(array (=> "A Point"=> "Another point"=> "After a space, another point"));
// use the data label array on the X axis
$PlotArea->AxisX->setDataPreprocessor($ArrayData);

// create the graph as "thumbnail of the original", best result using GD2
$Graph->Thumbnail(400300);

// output the Graph
$Graph->Done();

?>


GraPHPite - Open Source PHP OO Graph Rendering Utility

SourceForge.net Logo