SVGGraph 3.17 - a PHP SVG graph library
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.
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 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.
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
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:
// 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.
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
|BarGraph||Vertical bars, optionally hyperlinked.|
|StackedBarGraph||Vertical bars, with multiple datasets stacked.|
|GroupedBarGraph||Vertical bars, with multiple datasets grouped side-by-side.|
|StackedGroupedBarGraph||Vertical bars, with both stacked and grouped datasets.|
|BarAndLineGraph||Grouped bar graph with multi-line graph.|
|StackedBarAndLineGraph||Stacked bar graph with multi-line graph.|
|Histogram||A series of bars that represent the spread of values.|
For more details and examples, see the bar graph page.
|Bar3DGraph||A 3D-looking version of the BarGraph type.|
|StackedBar3DGraph||3D vertical bars, with multiple datasets stacked.|
|GroupedBar3DGraph||3D vertical bars, with multiple datasets grouped side-by-side.|
|StackedGroupedBar3DGraph||3D vertical bars, with both stacked and grouped datasets.|
|CylinderGraph||Vertical 3D cylinder-shaped bars.|
|StackedCylinderGraph||Cylinder-shaped version of stacked bar graph.|
|GroupedCylinderGraph||Cylinder-shaped version of grouped bar graph.|
|StackedGroupedCylinderGraph||Cylinder-shaped version of stacked and grouped bar graph.|
|HorizontalBar3DGraph||A 3D-looking version of the HorizontalBarGraph type.|
|HorizontalStackedBar3DGraph||A 3D-looking version of the HorizontalStackedBarGraph type.|
|HorizontalGroupedBar3DGraph||A 3D-looking version of the HorizontalGroupedBarGraph type.|
For more details and examples, see the 3D bar graph page.
|HorizontalBarGraph||Horizontal bars, optionally hyperlinked.|
|HorizontalStackedBarGraph||Horizontal bars, with multiple datasets in-line.|
|HorizontalGroupedBarGraph||Horizontal bars, with multiple datasets grouped vertically.|
|PopulationPyramid||A horizontal bar graph with the bars drawn from a central axis, used to show male and female populations and ages.|
For more details and examples, see the horizontal bar graph page.
|LineGraph||A line joining the data points, with optionally hyperlinked markers at the data points.|
|MultiLineGraph||Multiple lines joining the data points in each data set, with optionally hyperlinked markers at the data points.|
|StackedLineGraph||Multiple lines joining data points, with the values from different data sets added together.|
|SteppedLineGraph||A line graph with its line going in horizontal steps.|
|MultiSteppedLineGraph||A multi-line graph with its lines going in horizontal steps.|
For more details and examples, see the line graph page.
|ScatterGraph||Markers drawn at arbitrary horizontal and vertical points.|
|MultiScatterGraph||Markers from multiple data sets drawn at arbitrary horizontal and vertical points.|
For more details and examples, see the scatter graph page.
|RadarGraph||A line joining the data points, measured from the centre point, with optionally hyperlinked markers at the data points.|
|MultiRadarGraph||Multiple lines joining the data points in each data set, measured from the centre point, with optionally hyperlinked markers at the data points.|
For more details and examples, see the radar graph page.
|PieGraph||A pie chart, with optionally hyperlinked slices and option to fade labels in/out when the pointer enters/leaves a slice.|
|Pie3DGraph||A 3D-looking version of the PieGraph type.|
|DonutGraph||A pie chart, with a hole in the centre where text can be displayed.|
|SemiDonutGraph||A donut graph that only uses half of the circle.|
|Donut3DGraph||A 3D donut graph.|
|SemiDonut3DGraph||A 3D semi-donut graph.|
|PolarAreaGraph||A pie chart where the area of the slice indicates the value instead of the slice angle.|
|PolarArea3DGraph||A 3D version of the PolarAreaGraph.|
|ExplodedPieGraph||A pie chart with slices pushed out from the centre point.|
|ExplodedPie3DGraph||A 3D version of the ExplodedPieGraph.|
|ExplodedDonutGraph||An exploded DonutGraph.|
|ExplodedSemiDonutGraph||An exploded SemiDonutGraph.|
|ExplodedDonut3DGraph||An exploded Donut3DGraph.|
|ExplodedSemiDonut3DGraph||An exploded SemiDonut3DGraph.|
For more details and examples, see the pie graph page.
|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.
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.