SVGGraph general settings

« Return to SVGGraph page

Many of the ways that things are displayed on the graphs may be changed by passing in an array of settings to the SVGGraph constructor:

require_once 'SVGGraph/autoloader.php';

$width = 500;
$height = 400;

$settings = array(
  'back_colour' => 'white',
  'graph_title' => 'Start of Fibonacci series'

$graph = new Goat1000\SVGGraph\SVGGraph($width, $height, $settings);

$graph->values(0, 1, 1, 2, 3, 5, 8, 13, 21);

A list of options that are valid for all types of graph and their default values are shown below. Sizes are always in pixels - you should not append 'px' or any other CSS units.

Because the settings are stored in a standard PHP array, numbers, boolean values (true and false) and NULL values should be used without surrounding quotes. All other values (except arrays) are strings, and should be quoted with either single or double quotes.

A full list of all available options, which can be filtered by graph type or tag, is available on the options index page.

Note: this page was added before the options index was created, and its contents are generated from a different list. New options will always be added to the options index, but might not make it to this page.

General options - Hide table

title NULL Contents of title tag, or NULL for none
description NULL Contents of desc tag, or NULL for none
auto_fit false If true, the SVG will scale to fit inside its container element
stroke_colour "rgb(0,0,0)" Colour of graph lines
stroke_width 1 Thickness of graph lines, 0 disables line drawing
stroke_dash[1] NULL Dash pattern for graph lines, NULL for complete lines
back_colour[2] "rgb(240,240,240)" Background colour of graph (use "none" for transparent)
back_round 0 Radius of rounded background edge
back_round_clip false If true, adds a clip path to the background rectangle to prevent drawing over the rounded corners
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:
image will be uniformly scaled to fit in width and height;
image will be tiled in blocks using width and height;
image will be stretched to fit width and height
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
svg_class NULL Class name for root SVG element, NULL for none
encoding "UTF-8" Sets the character encoding in the XML declaration
exception_details false When enabled, some extra details about thrown exceptions are displayed
exception_throw false When enabled, exceptions are not caught by SVGGraph
decimal "." Decimal point character for axis labels, etc.
thousands "," Thousands separator for axis labels, etc.
force_assoc false When enabled, treats values array as associative even if its keys are numeric
dataset NULL Single dataset or array of datasets to be enabled for graph, or NULL to use all datasets
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_stroke_colour NULL Tooltip border colour, NULL to use tooltip_colour
tooltip_back_colour[2] "#ffffcc" Tooltip rectangle background colour
tooltip_font "Arial" 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
tooltip_callback NULL Name of callback function for formatting tooltip text. The function will be called with three arguments: callback($dataset, $key, $value). The function should return a text string to display or NULL for no tooltip. Takes precedence over structured data tooltip values.
units_tooltip NULL Units shown after value on tooltip
units_before_tooltip NULL Units shown before value on tooltip
units_tooltip_key NULL Units shown after key (X) value on tooltip
units_before_tooltip_key NULL Units shown before key (X) value on 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 "Arial" 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")
show_legend true Enables displaying the legend. Entries for the legend must be supplied using legend_entries or structured data legend_text options.
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[2] "rgb(255,255,255)" Colour of legend background
legend_round 0 Radius of rounded corners for legend border
legend_shadow_opacity 0.3 How dark the shadow is (1 = black, 0 = no shadow)
legend_font "Arial" 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_columns 1 Number of columns to display entries in
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" or "right")
legend_draggable true Makes the legend draggable with the mouse
legend_autohide false Makes the legend hide when the cursor is over it
legend_show_empty false Set to TRUE to display legend entries for 0 or NULL values
legend_order "auto" Order of entries in legend
legend_padding_x NULL Horizontal padding inside legend, NULL to use legend_padding value
legend_padding_y NULL Vertical padding inside legend, NULL to use legend_padding value
legend_spacing NULL Vertical spacing between entries, NULL to use legend_padding value
legend_column_spacing NULL Horizontal spacing between legend columns, NULL to use legend_padding value
legend_entry_spacing NULL Horizontal spacing between legend text and graphic, NULL to use legend_padding value
legend_title_spacing NULL Vertical spacing between title and entries, NULL to use legend_padding value
structured_data false Set to TRUE to enable structured data support
structure NULL Sets the structure to use with structured data
datetime_keys false Turns on parsing of keys as date/time values. Enables the date/time axis for grid-based graphs
datetime_key_format NULL Parse format for use with datetime_keys option. The format string should be one supported by the DateTime::createFromFormat() function.
minify true Removes extra whitespace from SVG content
minify_js NULL Either TRUE to use a built-in Javascript minifier, or a callback function for minifying the code. The callback function must accept a string of Javascript as input and return the minified code as a string
empty_use true Outputs <use ...></use> instead of <use .../> to work around Safari bug
no_tspan false When enabled, outputs multiple <text> elements instead of <tspan> elements for multi-line text
semantic_classes false When enabled, adds classes around bars, pie slices, graph lines and markers for use in scripting
shape NULL Shapes to be drawn on the graph. See the shapes page for details
no_font_metrics false Disables the use of font metrics files for estimating the size of text
show_context_menu false Enables display of context menu on right-click or long touch
context_global NULL Default context menu, or FALSE for no menu
context_colour "black" Text and border colour for context menu
context_stroke_width 1 Thickness of context menu border
context_back_colour "#fff" Colour of context menu background
context_link_colour "#00f" Colour of links in context menu
context_link_hover_colour "#f00" Colour of link in context menu when cursor is over it
context_link_target "_top" Target for context menu links
context_link_underline true Underlines context menu links
context_round 0 Radius of context menu rounded corners
context_font "Arial" Font used for context menu
context_font_size 15 Font size for context menu
context_font_weight "normal" Font weight for context menu
context_padding 3 Padding inside context menu box
context_padding_x NULL Horizontal padding inside context menu box
context_padding_y NULL Vertical padding inside context menu box
context_spacing 3 Spacing between context menu items
context_shadow_opacity 0.3 Opacity of shadow under context menu box
context_document_menu false Set to TRUE to enable the standard browser context menu as default
context_min_width 60 Minimum width of context menu box
context_callback NULL Callback function for context menu contents
context_mouseleave 100 Delay between cursor leaving document and context menu closing, or 0 for no delay
show_shadow false Set to TRUE to enable drop shadow effect
shadow_offset_x 5 Horizontal shadow offset
shadow_offset_y 5 Vertical shadow offset
shadow_opacity 0.5 Opacity of shadow effect
shadow_blur 3 Amount of blurring on shadow effect
show_data_labels false Displays labels for bars, markers, pie slices
data_label_type "plain" The style of label to use. Options are "plain", "box", "bubble", "line", "circle", "square", "linecircle", "linebox", "linesquare" and "line2"
data_label_space 3 The space between the label and the data item.
data_label_font "Arial" Font used for label
data_label_font_size 10 Font size for data label
data_label_font_adjust 0.6 Font adjust value for label text
data_label_font_weight "normal" Font weight for data label
data_label_colour "rgb(0,0,0)" Text colour for data label
data_label_colour_outside NULL Text colour for data label when outside bar/slice. NULL for same colour as when inside
data_label_back_colour NULL Colour for label text border, or NULL for none
data_label_back_colour_outside NULL Colour for label text border when outside bar/slice, or NULL for same as when inside
data_label_position "top" Position of data label relative to bar/marker/slice. See the data labels page for details
data_label_angle 0 Text angle for data labels
data_label_padding 3 Space between data label text and edge of label box
data_label_padding_x NULL Horizontal space between data label text and edge of label box, overrides data_label_padding
data_label_padding_y NULL Vertical space between data label text and edge of label box, overrides data_label_padding
data_label_round 0 Radius of rounded corners for enclosed labels, or specifies a circular bounding box for plain text labels
data_label_fill "white" Background colour, gradient or pattern for box or bubble style data labels
data_label_outline_colour "rgb(0,0,0)" Edge colour for data labels
data_label_outline_thickness 1 Line thickness for data labels
data_label_tail_length 3 Length of label tail in pixels, or "auto" for automatic length calculation
data_label_tail_width 5 Thickness of tail
data_label_tail_end "flat" Type of line ending for labels with filled-line tails. Options are: "flat", "taper", "point", "filled", "diamond", "arrow", "tee" and "round"
data_label_tail_end_width 10 Width of tail ending in pixels
data_label_tail_end_angle 45 Angle of tail ending lines
data_label_shadow_opacity 0.3 Opacity of data label shadows
data_label_fade_in_speed 0 Fade in speed for data labels
data_label_fade_out_speed 0 Fade out speed for data labels
data_label_click false Set to TRUE to enable show/hide labels by clicking bar/marker/slice
data_label_popfront false Set to TRUE to pop the label of the bar/marker/slice under the cursor to top
data_label_filter NULL Filters the list of data labels to be displayed. See the data labels page for details
data_label_max_count 100 Maximum number of data labels to display for a dataset (after filtering)
data_label_min_space 0 Sets the minimum space required for a label to be shown. For vertical bars this is the height of the bar, for horizontal bars it is the width and for pie slices it is the angle in degrees. Has no effect on line and scatter graphs.
data_label_callback NULL Name of callback function for formatting data label text. The function will be called with three arguments: callback($dataset, $key, $value). The function should return a text string to display or NULL for no label. Takes precedence over structured data label values.
data_label_same_size false Set to TRUE to display all labels the same size, or an array of boolean values to set the option for each dataset separately
units_label NULL Units string to display after value in data labels
units_before_label NULL Units string to display before value in data labels
label NULL Custom labels to display on the graph. See the custom labels page for details.
General options

For details of the options specific to each type of graph, please visit the relevant page:

For more examples and for complete explanations of some of these options, take a look at the background image page, the axis and grid dimensions page, the titles and axis labels page and the legends page.

« Back to top of page Bar graphs »