SVGGraph Pie Graphs
SVGGraph currently contains these classes for drawing pie graphs: PieGraph, Pie3DGraph. An example of each type is shown below.
Example code
Here are the settings and PHP code used to generate the graphs above:
require_once('includes/SVGGraph.php'); $settings = array( 'back_colour' => '#eee', 'stroke_colour' => '#000', 'back_stroke_width' => 0, 'back_stroke_colour' => '#eee', 'back_image' => 'images/svgbg.png', 'axis_colour' => '#333', 'axis_overlap' => 2, 'axis_font' => 'Georgia', 'axis_font_size' => 10, 'grid_colour' => '#666', 'label_colour' => '#000', 'pad_right' => 20, 'pad_left' => 20, 'link_base' => '/', 'link_target' => '_top', 'show_labels' => true, 'show_label_amount' => true, 'label_font' => 'Georgia','label_font_size' => '11', 'sort' => false ); $values = array('Dough' => 30, 'Ray' => 50, 'Me' => 40, 'So' => 25, 'Far' => 45, 'Lard' => 35); $colours = array('#ccf','#699','#93c','#996','#f39','#0f3','#339'); $links = array('Dough' => 'jpegsaver.php', 'Ray' => 'crcdropper.php', 'Me' => 'svggraph.php'); $graph = new SVGGraph(300, 200, $settings); $graph->colours = $colours; $graph->Values($values); $graph->Links($links); $graph->Render('PieGraph');
This is not the actual code used - I have adapted it to make it easier to copy
and paste it into a new file to try for yourself. To change the type of graph
generated, change 'PieGraph' in the final call to $graph->Render
to 'Pie3DGraph' (or one of the bar or line types).
Label fading
The options to fade labels in and out when the mouse enters and leaves a pie slice have been in SVGGraph for a long time, but in version 2.5 the new event handler method makes them work a lot better. In the older version only the pie slice had the event handler, meaning that the fading would not work when the mouse was over the label. Using the new event handler, a transparent copy of the pie slice is placed on top, and this has the event handler applied to it instead.
label_fade_in_speed = 30label_fade_out_speed = 15
In the example above, the label_fade_in_speed option is set
to 30, and the label_fade_out_speed is set to 15. These numbers
are the percentage change in opacity of the label with each time slice.
The maximum value of 100 means the label will change from 100% to 0% opacity or from 0% to 100% opacity as soon as the timer function is called - which is set to every 50ms (20 frames per second).
Settings
These options are common to all graph types:
| Option | Default | Description |
|---|---|---|
title |
NULL |
Contents of title tag, or NULL for none |
description |
NULL |
Contents of desc tag, or NULL for none |
stroke_colour |
rgb(0,0,0) |
Colour of graph lines |
stroke_width |
1 |
Thickness of graph lines, 0 disables line drawing |
back_colour |
rgb(240,240,240) |
Background colour of graph |
back_round |
0 |
Radius of rounded background edge |
back_stroke_width |
1 |
Thickness of background edge |
back_stroke_colour |
rgb(0,0,0) |
Colour of background edge |
back_image |
NULL |
Image to use for background (NULL for none). See the SVGGraph background image page for details. |
back_image_width |
100% |
Width of background image |
back_image_height |
100% |
Height of background image |
back_image_opacity |
1.0 |
Opacity of background image (0.0-1.0) |
back_image_top |
0 |
Top offset of background image |
back_image_left |
0 |
Left offset of background image |
back_image_mode |
auto |
Background image display method. Options are:
|
pad_top |
10 |
Space at top of graph |
pad_bottom |
10 |
Space at bottom of graph |
pad_left |
10 |
Space to left of graph |
pad_right |
10 |
Space to right of graph |
link_base |
|
Prepended to all links |
link_target |
_blank |
Link target frame |
namespace |
false |
Option to use the svg: namespace prefix |
doctype |
false |
Option to output the DOCTYPE |
show_tooltips |
true |
Enables display of tooltips over graph markers |
tooltip_colour |
black |
Tooltip text/border colour |
tooltip_stroke_width |
1 |
Tooltip border thickness |
tooltip_back_colour |
#ffffcc |
Tooltip rectangle background colour |
tooltip_font |
sans-serif |
Font for tooltips |
tooltip_font_weight |
normal |
Tooltip font weight |
tooltip_font_size |
10 |
Tooltip font size |
tooltip_padding |
3 |
Tooltip rectangle padding |
tooltip_round |
0 |
Radius of rounded tooltip corner |
tooltip_shadow_opacity |
0.3 |
Opacity of tooltip shadow (0.0-1.0, 0 disables shadow) |
tooltip_offset |
10 |
Distance between cursor and tooltip |
compat_events |
false |
Set to TRUE to fall back to inline event handlers, required by Adobe IE plugin |
graph_title |
NULL |
Title displayed on the graph |
graph_title_font |
sans-serif |
Font for graph title |
graph_title_font_size |
12 |
Font size for graph title |
graph_title_font_weight |
normal |
Font weight for graph title |
graph_title_space |
10 |
Spacing around graph title |
graph_title_colour |
rgb(0,0,0) |
Colour of graph title |
graph_title_position |
top |
Where to show graph title ("top", "bottom", "left", "right") |
legend_entries |
NULL |
Array of entries for the legend |
legend_position |
top right |
Position of the legend. Supports "top", "bottom", "left", "right", "inner", "outer" and pairs of X and Y offsets |
legend_stroke_width |
1 |
Thickness of legend border |
legend_stroke_colour |
rgb(0,0,0) |
Colour of legend border |
legend_back_colour |
rgb(255,255,255) |
Colour of legend background |
legend_round |
0 |
Radius of rounded corners for legend border |
legend_font |
sans-serif |
Font for legend entries |
legend_font_weight |
normal |
Font weight for legend entries |
legend_font_size |
10 |
Font size for legend entries |
legend_font_adjust |
0.6 |
Ratio of font width to height |
legend_colour |
rgb(0,0,0) |
Colour of legend entries text |
legend_padding |
5 |
Amount of spacing between entries in legend |
legend_entry_width |
20 |
Width of legend entry box |
legend_entry_height |
20 |
Height of legend entry box |
legend_title |
|
Title for legend |
legend_title_font |
NULL |
Font for legend title (NULL = use legend_font) |
legend_title_font_size |
NULL |
Font size for legend title (NULL = use legend_font_size) |
legend_title_font_weight |
bold |
Font weight for legend title |
legend_title_font_adjust |
NULL |
Ratio of font width to height (NULL = use legend_font_adjust) |
legend_title_colour |
NULL |
Colour of legend title (NULL = use legend_colour |
legend_text_side |
right |
Which side of the entry box the text should be on ("left", "right") |
legend_draggable |
true |
Makes the legend draggable with the mouse |
legend_autohide |
false |
Makes the legend hide when the cursor is over it |
The following table lists the other options relevant to the pie graph types:
| Option | Default | Description |
|---|---|---|
aspect_ratio |
1.0 |
Ratio of height/width (or auto to fill area) |
sort |
true |
Sorts the pie slices, largest first |
reverse |
false |
Slices are drawn anti-clockwise instead of clockwise |
start_angle |
0 |
Angle in degrees to start the first slice at |
show_labels |
true |
Slice labelling on/off option |
show_label_amount |
false |
Display slice value on/off option |
show_label_percent |
false |
Display slice percentage on/off option |
label_colour |
white |
Colour of label text |
label_back_colour |
NULL |
Label background colour |
label_font |
sans-serif |
Font for labels |
label_font_weight |
bold |
Label font weight |
label_font_size |
18 |
Label font size |
label_fade_in_speed |
0 |
Speed to fade in labels (1-100, 0 disables) |
label_fade_out_speed |
0 |
Speed to fade out labels, if fading in is enabled |
label_position |
0.75 |
Distance of label from centre |
depth[1] |
10 |
Depth of the pie slice |
- [1]Only used by Pie3DGraph.
