Documentation Home
Examples
Pie Charts
Overview
Customizing the chart
Function Reference
Examples
Line & Bar Graphs
Overview
Adding data
Customizing the bars
Customizing the axes
Function Reference
Support
Installation
Version History
Technical Support

Bar Graph PHP Class function reference

Function List

Bar graph data functions
setTitle ( title:string )
addColumn ( name:string )
addColumns ( name:array of strings )
doBarSeries ( name:string, col1:colour, col2:colour )
doStackedBarSeries ( name:string, col1:colour, col2:colour )
doLineSeries ( name:string, col:colour )
addData ( column:string, value:number )
addDataToSeries ( series:string, column:string, value:number )
setSeriesShownInLegend ( shown:boolean )
Image functions
drawPNG ( width:number, height:number, thumb_w:number, thumb_h:number )
drawJPEG ( width:number, height:number, quality:number, thumb_w:number, thumb_h:number )
savePNG ( filename:string, width:number, height:number, thumb_w:number, thumb_h:number )
saveJPEG ( filename:string, width:number, height:number, quality:number, thumb_w:number, thumb_h:number )
Customising the look of the graph
setBackground ( bg1:colour, bg2:colour )
setPadding ( padding:number )
setDefaultFont ( font:string )
setTitleStyle ( fontName:string, size:int, colour:colour )
setTitlePosition ( xpos:number, ypos:number )
setLegendWidth ( width:number )
setLegendTextStyle ( font:string, size:number, font:colour, between:number )
setLegendKeyStyle ( size:number, padding:number )
setLegendBoxStyle ( backgroundCol:colour, borderCol:colour, padding:number )
setLegendPosition ( xpos:number, ypos:number )
setColumnSpacing ( spacing:number )
setStackedBarSpacing ( spacing:number )
setStackedBarOverlap ( overlap:number )
setBarColour ( col1:colour, col2:colour )
setLineColour ( col:colour )
setLineStyle ( thickness:number, dotsize:number )
setValueStyle ( font:string, size:number, col:colour, pos:number, angle:number )
Axis layout & style
setXAxisTextStyle ( font:string, size:number, col:colour, angle:number )
setYAxisTextStyle ( font:string, size:number, col:colour, angle:number )
setXAxisTitleStyle ( font:string, size:number, col:colour )
setYAxisTitleStyle ( font:string, size:number, col:colour )
setYAxisMaximum ( max:number/boolean )
setYAxisMinimum ( min:number/boolean )
setLeftAxisTitle ( title:string )
setRightAxisTitle ( title:string )
setTopAxisTitle ( title:string )
setBottomAxisTitle ( title:string )
setGraphOrientation ( orientation:number )
clearAxes ( )
setLeftAxis ( axis:string )
setRightAxis ( axis:string )
setTopAxis ( axis:string )
setBottomAxis ( axis:string )

Bar graph data functions

The first thing to do when you define the data for a bar graph is to create the columns. This can be done using the addColumn or addColumns functions.
Then, you can create a graph with a single series (displayed as a single bar in each column) or with multiple series (displayed as stacked bars or side-by-side bars in each column)

setTitle ( title='' )

Sets the title to display in the image.
Parameters
  Type Default  
title string  
The title to display. If it is too long for one line it will be split onto multiple lines.

addColumn ( name )

Adds a column to the graph.
Parameters
  Type Default  
name string  
The name of the column, as it will appear along the X axis.
Notes
This can be used in combination with addColumns, both of these functions just add the columns onto the end of the current list of columns.

addColumns ( name )

Adds a set of columns to the graph.
Parameters
  Type Default  
name array of strings  
PHP array of column names, as they will appear along the X axis.
Notes
This can be used in combination with addColumn, both of these functions just add the columns onto the end of the current list of columns.
Examples
$chart->addColumns( array( 2001, 2002, 2003, 2004, 2005, 2006 ) );

doBarSeries ( name, col1, col2='same as col1' )

Starts a new series of data.
Parameters
  Type Default  
name string  
Name of the series, as it will appear in the legend.
col1 colour  
Colour at the top of the bar
col2 colour same as col1
Colour at the bottom of the bar
Notes
This function does not need to be called if the bar graph only has one series. To set the colour of the bars if there is only one series, use setBarColour.

doStackedBarSeries ( name, col1, col2='same as col1' )

Starts a new series of data, with the bars stacked on top of the last series. You can stack any number of bars on top of each other by repeatedly using this function.
Parameters
  Type Default  
name string  
Name of the series, as it will appear in the legend.
col1 colour  
Colour at the top of the bar
col2 colour same as col1
Colour at the bottom of the bar

doLineSeries ( name, col )

Starts a new series of data, which will be drawn as a line graph.
Parameters
  Type Default  
name string  
Name of the series, as it will appear in the legend.
col colour  
Colour of the line

addData ( column, value )

Adds a data item to the bar graph. After starting a series, add a data item for each column.
Parameters
  Type Default  
column string  
The name of the column this data is for.
value number  
The value of this data item.

addDataToSeries ( series, column, value )

v1.04 
Adds a data item to the specified series.
Parameters
  Type Default  
series string  
The name of the series to add this data to.
column string  
The name of the column this data is for.
value number  
The value of this data item.
Notes
It is often useful to create all the series first and add to them all at once, instead of filling each series with all it's values in turn. Here is an example of using addDataToSeries.

setSeriesShownInLegend ( shown=true )

v1.02 
Sets whether the current series should be listed in the legend.
Parameters
  Type Default  
shown boolean true
Whether the current series is listed.

Image functions

drawPNG ( width, height, thumb_w=0, thumb_h=0 )

Outputs a PNG image to the web browser, including the Content-type header.
Parameters
  Type Default  
width number  
Width of the image in pixels.
height number  
Height of the image in pixels.
thumb_w number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
thumb_h number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
Examples
$chart->drawPNG( 500, 400 );
Draws a chart at 500x400 pixels, then sends it to the web browser as a PNG image.
$chart->drawPNG( 500, 400, 0, 100 );
Draws a chart at 500x400 pixels, then scales the image down to 100 pixels high before sending to the web browser.

drawJPEG ( width, height, quality=75, thumb_w=0, thumb_h=0 )

Outputs a JPEG image to the web browser, including the Content-type header.
Parameters
  Type Default  
width number  
Width of the image in pixels.
height number  
Height of the image in pixels.
quality number 75
JPEG Quality - from 0 (lowest quality, small file) to 100 (best quality, large file)
thumb_w number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
thumb_h number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
Examples
$chart->drawJPEG( 500, 400, 90 );

savePNG ( filename, width, height, thumb_w=0, thumb_h=0 )

Saves the chart as a PNG file.
Parameters
  Type Default  
filename string  
Name of the file.
width number  
Width of the image in pixels.
height number  
Height of the image in pixels.
thumb_w number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
thumb_h number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
Notes
The filename can be specified with an absolute path, or with a relative path, which is relative to the script which is being requested by the Web browser.
Examples
$chart->savePNG( 'chart1.png', 500, 400 );
Saves the chart as chart1.png in the same directory as the PHP script which is being executed.

saveJPEG ( filename, width, height, quality=75, thumb_w=0, thumb_h=0 )

Saves the chart as a JPEG file.
Parameters
  Type Default  
filename string  
Name of the file.
width number  
Width of the image in pixels.
height number  
Height of the image in pixels.
quality number 75
JPEG Quality - from 0 (lowest quality, small file) to 100 (best quality, large file)
thumb_w number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
thumb_h number 0
If you want to generate a thumbnail image sepcify either the width or the height. v1.04
Notes
The filename can be specified with an absolute path, or with a relative path, which is relative to the script which is being requested by the Web browser.
Examples
$chart->saveJPEG( 'images/charts/chart1.jpg', 500, 400 );
Saves the chart as chart1.jpg in the images/charts directory, relative to the PHP script which is being executed.

Customising the look of the graph

The background, title, axes and legend can be customised.

setBackground ( bg1, bg2='same as bg1' )

Sets the background colour of the image, allowing you to create a vertical gradient by specifying a top and bottom colour.
Parameters
  Type Default  
bg1 colour  
Colour of background at the top of the image
bg2 colour same as bg1
Colour of background at the bottom of the image. If not specified, the background is the solid colour specified by .
Notes
Colours are specified as hexadecimal HTML colours.
Examples
$chart->setBackground( '99CCFF' );
Sets the background to light blue.
$chart->setBackground( 'DDDDDD', '999999' );
Sets the background to a gradient from light grey to slightly darker grey.

setPadding ( padding=20 )

Controls the spacing between the elements of the image - the chart, the title and the legend, and also the distance between these elements and the edge of the image.
Parameters
  Type Default  
padding number 20
Size of the padding in pixels.

setDefaultFont ( font )

v1.04b 
Sets the default font which will be used for the title, legend and any other text if you do not explicitly specify fonts for them. ChartLogix will look in the same directory as chartlogix.inc.php if you specify a font name without a path.
Parameters
  Type Default  
font string  
Font to use as the default

setTitleStyle ( fontName='Arial', size=15, colour=000000 )

Sets the style of the title.
Parameters
  Type Default  
fontName string Arial
Name of the font to use.
size int 15
Size of the font in points
colour colour 000000
Colour of the title, specified as a hexadecimal HTML colour.
Examples
$chart->setTitleStyle( "Verdana", 20, '000066' );
Sets the title style to Verdana, size 20, dark blue.

setTitlePosition ( xpos=0, ypos=0 )

Sets the position and alignment of the title
Parameters
  Type Default  
xpos number 0
Horizontal alignment of the title: -1 = Left aligned
0 = Centred
1 = Right aligned
ypos number 0
Vertical position 0 = Top
1 = Bottom

setLegendWidth ( width=40 )

Parameters
  Type Default  
width number 40
Percentage of the width of the image taken up by the legend.
Notes
Setting the legend width to 0 will hide the legend.
Examples
$chart->setLegendWidth( 50 );
Sets the legend to be 50% of the width of the image.

setLegendTextStyle ( font='Arial', size=10, font=000000, between=10 )

Sets the style of the text in the legend.
Parameters
  Type Default  
font string Arial
Font to use in the legend text.
size number 10
Size of text in points.
font colour 000000
Colour of the text, specified as a hexadecimal HTML colour.
between number 10
Spacing between items in the legend.
Examples
$chart->setLegendTextStyle( "Verdana", 8, '663300', 10 );

setLegendKeyStyle ( size=10, padding=10 )

Sets the style of the boxes next to the items in the legend.
Parameters
  Type Default  
size number 10
Size of the coloured squares.
padding number 10
Horizontal distance between the coloured squares and the text next to them.

setLegendBoxStyle ( backgroundCol, borderCol, padding )

Sets the style of the legend box.
Parameters
  Type Default  
backgroundCol colour  
Background colour.
borderCol colour  
Border colour.
padding number  
Padding between the legend box border and the contents of the box.
Examples
$chart->setLegendBoxStyle( 'FFFFCC', '333333', 20 );
Gives the legend box a light yellow background, dark grey border, and 20 pixels of padding.

setLegendPosition ( xpos=1, ypos=0 )

Sets the position of the legend.
Parameters
  Type Default  
xpos number 1
Horizontal position of legend. 0 = Left
1 = Right
ypos number 0
Vertical alignment of the title: -1 = Top
0 = Middle
1 = Bottom
Examples
$chart->setLegendPosition( 0, 0 );
Sets the legend to be in the top left corner of the image.

setColumnSpacing ( spacing=25 )

Sets the spacing either side of the bars within each column of the graph.
Parameters
  Type Default  
spacing number 25
Spacing, specified as a percentage of the width of the bars.
Examples
$chart->setColumnSpacing( 100 );
Sets the spacing either side of the bar to be the same width as the bar itself, so the bar takes up one third of the total width of each column.
$chart->setColumnSpacing( 50 );
Sets the spacing either side of the bar to be the half the width as the bar itself, so the bar takes up one half of the total width of each column.

setStackedBarSpacing ( spacing=0 )

Sets the spacing between bars when there are multiple stacks.
Parameters
  Type Default  
spacing number 0
Spacing, specified as a percentage of the width of the bars.

setStackedBarOverlap ( overlap=0 )

Sets the overlap of the bars when there are multiple stacks.
Parameters
  Type Default  
overlap number 0
Overlap, specified as a percentage of the width of the bars. 0 is no overlap, 100 is complete overlap.

setBarColour ( col1, col2='same as col1' )

Sets the colour of the bars. If two colours are specified, the bar will be coloured with a gradient from the top to the bottom. If this is used after a call to doBarSeries it sets the colour for the current series.
Parameters
  Type Default  
col1 colour  
Colour at the top of the bar.
col2 colour same as col1
Colour at the bottom of the bar.

setLineColour ( col )

Sets the colour of the line graph, call this function after doLineSeries.
Parameters
  Type Default  
col colour  
Colour of the line.

setLineStyle ( thickness=4, dotsize=7 )

Sets the style of the line graph, call this function after doLineSeries.
Parameters
  Type Default  
thickness number 4
Thickness of the line in pixels.
dotsize number 7
Width and height of the dots in pixels.

setValueStyle ( font='', size='', col=000000, pos=1, angle=0 )

v1.04 
Allows labels to be added to the bars showing their values - these labels can be placed above the bar or inside the bar, and the text can be horizontal or vertical. Each series can have it's own value style settings, or the same settings can be used for all.
Parameters
  Type Default  
font string  
Font to use for the labels
size number  
Size of the font
col colour 000000
Colour of the text labels
pos number 1
Position of the text labels 1 = Above bars
2 = Inside bars, at the top
3 = Inside bars, centred
4 = Inside bars, at the bottom
angle number 0
The angle of the text - from 0 (horizontal), up to 90 (vertical)
Notes
Call setValueStyle() with no parameters to turn off displaying the values.

Axis layout & style

setXAxisTextStyle ( font='Arial', size=10, col=000000, angle=0 )

Sets the text style of the horizontal axis
Parameters
  Type Default  
font string Arial
Font to use for the labels
size number 10
Size of the text in points
col colour 000000
Colour of the text
angle number 0
Angle of the text, from 0 (horizontal) to 90 (vertical)

setYAxisTextStyle ( font='Arial', size=10, col=000000, angle=0 )

Sets the text style of the vertical axis
Parameters
  Type Default  
font string Arial
Font to use for the labels
size number 10
Size of the text in points
col colour 000000
Colour of the text
angle number 0
Angle of the text, from 0 (horizontal) to 90 (vertical)

setXAxisTitleStyle ( font='arial.ttf', size=12, col=000000 )

v1.04 
Sets the style of the title shown on the X Axis
Parameters
  Type Default  
font string arial.ttf
Path to TTF font file to use for the title
size number 12
Size of the font
col colour 000000
Colour of the font

setYAxisTitleStyle ( font='arial.ttf', size=12, col=000000 )

v1.04 
Sets the style of the title shown on the Y Axis
Parameters
  Type Default  
font string arial.ttf
Path to TTF font file to use for the title
size number 12
Size of the font
col colour 000000
Colour of the font

setYAxisMaximum ( max=false )

v1.04 
Sets the maximum value of the Y-axis. By default the Y-axis scales automatically with the data but this function lets you override the default behaviour.
Parameters
  Type Default  
max number/boolean false
Maximum value for the Y-Axis, or false to use the automatic default.

setYAxisMinimum ( min=false )

v1.05 
Sets the minimum value of the Y-axis. By default the Y-axis automatically starts at 0 unless there are any data values which are negative.
Parameters
  Type Default  
min number/boolean false
Minimum value for the Y-Axis, or false to use the automatic default.

setLeftAxisTitle ( title='' )

v1.04 
Sets the axis title to appear on the left hand edge of the graph
Parameters
  Type Default  
title string  
Title for this axis

setRightAxisTitle ( title='' )

v1.04 
Sets the axis title to appear on the right hand edge of the graph
Parameters
  Type Default  
title string  
Title for this axis

setTopAxisTitle ( title='' )

v1.04 
Sets the axis title to appear on the top edge of the graph
Parameters
  Type Default  
title string  
Title for this axis

setBottomAxisTitle ( title='' )

v1.04 
Sets the axis title to appear on the bottom edge of the graph
Parameters
  Type Default  
title string  
Title for this axis

setGraphOrientation ( orientation )

v1.04 
Provides a simple way to switch between vertical and horizontal bar charts.
Parameters
  Type Default  
orientation number  
0 = Vertical graph (default)
1 = Horizontal graph

clearAxes ( )

v1.04 
Removes the default axes, ready for you to place the axes around the edge of the graph manually using the setLeftAxis, setRightAxis, setTopAxis and setBottomAxis functions.

setLeftAxis ( axis )

v1.04 
Sets the axis to appear on the left hand edge of the graph (by default this is the Y Axis, running up).
Parameters
  Type Default  
axis string  
Axis to display along the left hand edge of the graph x = X Axis
y = Y Axis

setRightAxis ( axis )

v1.04 
Sets the axis to appear on the right hand edge of the graph (by default no axis is displayed there).
Parameters
  Type Default  
axis string  
Axis to display along the right hand edge of the graph x = X Axis
y = Y Axis

setTopAxis ( axis )

v1.04 
Sets the axis to appear on the top edge of the graph (by default no axis is displayed there).
Parameters
  Type Default  
axis string  
Axis to display along the top edge of the graph x = X Axis
y = Y Axis

setBottomAxis ( axis )

v1.04 
Sets the axis to appear on the bottom edge of the graph (by default this is the X Axis, running right).
Parameters
  Type Default  
axis string  
Axis to display along the bottom edge of the graph x = X Axis
y = Y Axis
Home  |  Online Store  |  Documentation  |  ChartLogix Features  |  Terms & Conditions Copyright © 2024 CubeLogix Ltd