SVGGraph function reference

« Return to SVGGraph page

Skip to:

SVGGraph only has a few functions because the appearance of the graph is mainly configured using the $settings array passed to the SVGGraph class constructor.

SVGGraph constructor

$graph = new SVGGraph($width, $height, $settings /* = null */);

Creates an instance of the main SVGGraph class, setting the width and height of the SVG image. $settings is an array of named options that determines the appearance of the graph. For details of what to put in the settings array, see the pages for each of the graph types and the General settings page.

Values

$graph->Values($value, $value, $value, ...);
$graph->Values($values);

Sets the list of values that are used to build the graph. Either pass in individual values separated by commas, or an array of values. See the Assigning data values section of the Using SVGGraph page for details.

$graph->Links($link, $link, $link, ...);
$graph->Links($links);

Sets link URLs for the bars, graph markers or pie graph slices. See the Adding hyperlinks section of the Using SVGGraph page for details.

Colours

$graph->Colours($colours);

Sets the array of colours, gradients and patterns to use for drawing and filling elements on the graph. See the Colours, gradients and patterns page for details of this and the other colour functions.

ColourSet function

$graph->ColourSet($dataset, $colours);

Sets the list of colours for a dataset. If there are more datasets on the graph than are specified using separate calls to ColourSet (or the other colour functions), then colour sets will be repeated. Using a NULL value for the $colours argument will remove the colour set (or range) for that dataset.

ColourRangeRGB function

$graph->ColourRangeRGB($dataset, $r1, $g1, $b1, $r2, $g2, $b2);

Sets a colour range for a dataset, the colours in between the start and end values being interpolated linearly between their red, green and blue values.

ColourRangeHSL function

$graph->ColourRangeHSL($dataset, $h1, $s1, $l1, $h2, $s2, $l2, $reverse /* = false */);

Sets a colour range for a dataset, using linear interpolation between the hue, saturation and lightness values. The hue is interpolated using the shorter arc of the colour wheel by default, setting $reverse to true will interpolate using the larger arc instead.

The pie graph on the right uses a HSL range to display the colour wheel. 0° is at the top (red), yellow is at 60°, green at 120°, cyan at 180°, blue at 240° and purple at 300°.

The saturation is a value between 0 and 1, and the lightness is also a value between 0 and 1. I won't attempt to explain what they do, since there is a handy Wikipedia page to do that for me.

ColourRangeRGBtoHSL function

$graph->ColourRangeRGBtoHSL($dataset, $r1, $g1, $b1, $r2, $g2, $b2, $reverse /* = false */);

Sets a colour range using HSL interpolation from RGB values. This function translates the red, green and blue components into the hue, saturation and lightness values required for a HSL range.

ColourRangeHexRGB function

$graph->ColourRangeHexRGB($dataset, $hex1, $hex2);

Sets a colour range using RGB interpolation from four character (e.g. "#fff") or seven character (e.g. "#ff00ff") hex codes. Invalid codes will be treated as black.

ColourRangeHexHSL function

$graph->ColourRangeHexHSL($dataset, $hex1, $hex2, $reverse /* = false */);

Sets a colour range using HSL interpolation from four character (e.g. "#fff") or seven character (e.g. "#ff00ff") hex codes. Invalid codes will be treated as black.

Render

$graph->Render($type, $header /* = true */, $content_type /* = true */);

Builds the graph, outputting it directly to the browser. The $type parameter must be one of the supported graph class names listed in Graph types.

Fetch

$svg = $graph->Fetch($type, $header /* = true */, $defer_js /* = true */);

Builds the graph, returning the SVG markup as a string. The $type parameter must be one of the supported graph class names listed in Graph types. By default the Javascript generated for the graph will be stored for later retrieval with the FetchJavascript function.

FetchJavascript

$javascript = $graph->FetchJavascript();

…or…

$javascript = SVGGraph::FetchJavascript();

Returns the block of Javascript code generated by previous calls to the Fetch function as a string, including the opening and closing <script> tags. When there is no Javascript code to include the function returns an empty string.

The second method calls FetchJavascript statically, which is useful when you do not have an instance of SVGGraph to use with the first method. Support for this syntax has been added in version 2.24.

« Back to top of page Colours, gradients and patterns »