SVGGraph 3.20 - a PHP SVG graph library

Skip to:

SVGGraph is an object-oriented PHP library for creating simple PHP graphs, released as open source under the LGPL v3 license. Here are some examples of different types of graph supported by SVGGraph.

DoughRayMeSoFarLard01020304050
BarGraph
05101520253035404550DoughRayMeSoFarLard
HorizontalBarGraph
DoughRayMeSoFarLard01020304050
Bar3DGraph
Dough$30Ray$50Me$40So$25Far$45Lard$35
Pie3DGraph
DoughRayMeSoFarLard01020304050
LineGraph
050100150200250300350400450500-20020406080
ScatterGraph

Requirements

PHP 5.4

SVGGraph 3.0 requires a minimum PHP version of 5.4. If you must use a PHP version lower than this, stick with a SVGGraph 2.x version. The SVGGraph 1.x branch supported PHP 4, but hopefully nobody is still using that.

JSON

JSON is a standard, bundled PHP extension that SVGGraph uses for parsing its font metrics files.

iconv and mbstring

These are character encoding PHP extensions used by SVGGraph to convert between character sets. SVGGraph will work without them, but could have trouble measuring text in non-western formats.

PCRE

PCRE (the preg_* functions) is a core PHP extension and you shouldn't be able to turn it off, but I'm listing it here for the sake of completeness.

Getting SVGGraph

There are several ways you can get hold of SVGGraph:

1. Download from this site:

2. Clone, download or browse the repository on GitHub:

3. Use Composer and Packagist to download and install SVGGraph from GitHub:

Older versions of SVGGraph are available from the downloads page if you cannot use the latest version for any reason.

Example graph code

Here is a basic example:

<?php
// SVGGraph 3 uses an autoloader and namespace
require 'svggraph/autoloader.php';
$graph = new Goat1000\SVGGraph\SVGGraph(640, 480);

$graph->colours(['red','green','blue']);
$graph->values(100, 200, 150);
$graph->links('/Tom/', '/Dick/', '/Harry/');
$graph->render('BarGraph');

This will create a SVG file containing a 640x480 bar graph with three hyperlinked bars.

Graph types

At the moment these types of graph are supported by SVGGraph - the class name of the type of graph you want to generate should be passed to the $graph->render() or $graph->fetch() function.

Bar graphs

Class name Description Example
BarGraph Vertical bars, optionally hyperlinked. BarGraph
StackedBarGraph Vertical bars, with multiple datasets stacked. StackedBarGraph
GroupedBarGraph Vertical bars, with multiple datasets grouped side-by-side. GroupedBarGraph
StackedGroupedBarGraph Vertical bars, with both stacked and grouped datasets. StackedGroupedBarGraph
Histogram A series of bars that represent the spread of values. Histogram

For more details and examples, see the bar graph page.

Bar and line graphs

Class name Description Example
BarAndLineGraph Grouped bar graph with multi-line graph. BarAndLineGraph
StackedBarAndLineGraph Stacked bar graph with multi-line graph. StackedBarAndLineGraph
ParetoChart A combined bar and line graph with sorted and totalled values. ParetoChart

For more details and examples, see the bar and line graph page.

3D Bar graphs

Class name Description Example
Bar3DGraph A 3D-looking version of the BarGraph type. Bar3DGraph
StackedBar3DGraph 3D vertical bars, with multiple datasets stacked. StackedBar3DGraph
GroupedBar3DGraph 3D vertical bars, with multiple datasets grouped side-by-side. GroupedBar3DGraph
StackedGroupedBar3DGraph 3D vertical bars, with both stacked and grouped datasets. StackedGroupedBar3DGraph
CylinderGraph Vertical 3D cylinder-shaped bars. CylinderGraph
StackedCylinderGraph Cylinder-shaped version of stacked bar graph. StackedCylinderGraph
GroupedCylinderGraph Cylinder-shaped version of grouped bar graph. GroupedCylinderGraph
StackedGroupedCylinderGraph Cylinder-shaped version of stacked and grouped bar graph. StackedGroupedCylinderGraph
HorizontalBar3DGraph A 3D-looking version of the HorizontalBarGraph type. HorizontalBar3DGraph
HorizontalStackedBar3DGraph A 3D-looking version of the HorizontalStackedBarGraph type. HorizontalStackedBar3DGraph
HorizontalGroupedBar3DGraph A 3D-looking version of the HorizontalGroupedBarGraph type. HorizontalGroupedBar3DGraph

For more details and examples, see the 3D bar graph page.

Horizontal bar graphs

Class name Description Example
HorizontalBarGraph Horizontal bars, optionally hyperlinked. HorizontalBarGraph
HorizontalStackedBarGraph Horizontal bars, with multiple datasets in-line. HorizontalStackedBarGraph
HorizontalGroupedBarGraph Horizontal bars, with multiple datasets grouped vertically. HorizontalGroupedBarGraph
PopulationPyramid A horizontal bar graph with the bars drawn from a central axis, used to show male and female populations and ages. PopulationPyramid

For more details and examples, see the horizontal bar graph page.

Line graphs

Class name Description Example
LineGraph A line joining the data points, with optionally hyperlinked markers at the data points. LineGraph
MultiLineGraph Multiple lines joining the data points in each data set, with optionally hyperlinked markers at the data points. MultiLineGraph
StackedLineGraph Multiple lines joining data points, with the values from different data sets added together. StackedLineGraph
SteppedLineGraph A line graph with its line going in horizontal steps. SteppedLineGraph
MultiSteppedLineGraph A multi-line graph with its lines going in horizontal steps. MultiSteppedLineGraph

For more details and examples, see the line graph page.

Scatter graphs

Class name Description Example
ScatterGraph Markers drawn at arbitrary horizontal and vertical points. ScatterGraph
MultiScatterGraph Markers from multiple data sets drawn at arbitrary horizontal and vertical points. MultiScatterGraph

For more details and examples, see the scatter graph page.

Radar graphs

Class name Description Example
RadarGraph A line joining the data points, measured from the centre point, with optionally hyperlinked markers at the data points. RadarGraph
MultiRadarGraph Multiple lines joining the data points in each data set, measured from the centre point, with optionally hyperlinked markers at the data points. MultiRadarGraph

For more details and examples, see the radar graph page.

Pie graphs

Class name Description Example
PieGraph A pie chart, with optionally hyperlinked slices and option to fade labels in/out when the pointer enters/leaves a slice. PieGraph
Pie3DGraph A 3D-looking version of the PieGraph type. Pie3DGraph
DonutGraph A pie chart, with a hole in the centre where text can be displayed. DonutGraph
SemiDonutGraph A donut graph that only uses half of the circle. SemiDonutGraph
Donut3DGraph A 3D donut graph. Donut3DGraph
SemiDonut3DGraph A 3D semi-donut graph. SemiDonut3DGraph
PolarAreaGraph A pie chart where the area of the slice indicates the value instead of the slice angle. PolarAreaGraph
PolarArea3DGraph A 3D version of the PolarAreaGraph. PolarArea3DGraph
ExplodedPieGraph A pie chart with slices pushed out from the centre point. ExplodedPieGraph
ExplodedPie3DGraph A 3D version of the ExplodedPieGraph. ExplodedPie3DGraph
ExplodedDonutGraph An exploded DonutGraph. ExplodedDonutGraph
ExplodedSemiDonutGraph An exploded SemiDonutGraph. ExplodedSemiDonutGraph
ExplodedDonut3DGraph An exploded Donut3DGraph. ExplodedDonut3DGraph
ExplodedSemiDonut3DGraph An exploded SemiDonut3DGraph. ExplodedSemiDonut3DGraph

For more details and examples, see the pie graph page.

Other miscellaneous graphs

Class name Description
FloatingBarGraph A bar graph where the top and bottom of each bar use separate data points.
HorizontalFloatingBarGraph A horizontal version of the FloatingBarGraph.
BubbleGraph A scatter graph where the markers are replaced by filled circles, their areas coming from another data point.
BoxAndWhiskerGraph A bar-like graph for displaying statistical distributions.
CandlestickGraph A floating bar graph with extra data points for displaying stock price changes.
EmptyGraph An empty SVG document that supports the label and shape options.
ArrayGraph A document containing multiple sub-graphs.

For more details and examples, see the other graphs page.

Help!

If you have trouble figuring out how to get your graph working from the details on these pages, or if you find any bugs or have suggestions for improvements, please contact me at the usual address, graham(at)goat1000.com.

Thanks to Pierre-Sylvain Luquet for his code submissions.

« Back to top of page Using SVGGraph »

This site uses cookies - details here.