baaChart User Guide

Index

   
Basic methods  
  baaChart Create new graph object
  setTitle Set title and subtitle for chart
  setYAxis Set y axis attributes
  setXAxis Set x axis attributes
  setXLabels Set x axis labels
  addDataSeries Add a series of data to the graph
  drawGraph Draw graph and send image to browser
Chart appearance  
  setBgColor Set image background colour
  setChartBgColor Set chart area background colour
  setChartBgColor2 Set second chart area colour for colour bands
  setGridColor Set colour for chart grid
  setSeriesColor Set colour for data series
  setTextColor Set colour for text
  setMargins Set margins around chart area
  setBgImagePos Set position of background image
  setBgImageAlpha Set transparency value for background image
Code samples and output  
Download class  
Download guide  

Method Reference



|index|
baaChart object baaChart (imageWidth [, imageHeight] [, bgImageFile] [, bgImageMode] [, clipX, clipY])
  imageWidth specifies the width of the chart image
  imageHeight [optional] If 0 or omitted the height is calculated such that height * 1.616 = width (Golden Mean)
  bgImageFile [optional] Path/Filename containing background image
  bgImageMode [optional] 0 = bgImage is resized to fit chart

1 = bgImage is clipped to fit. If smaller than chart it is centered in chart area. This position can be changed using setBgImagePos()

2 = the bgImage will be tiled to fill the chart area

  clipX, clipY [optional] top-left x,y coordinates of the area to be clipped if other than 0,0
   


Creates a baaChart object whose size is specified by the parameters. The default image background is white (non-transparent). The chart area is created within this area subject to the margin sizes. An optional background image can be specified. If a bgImage is used, margin and chart area background colors will be transparent.

Default values for the new object are

margins
top 50, left 80, bottom 40, right 20
chart background
alternating pale grey bands
text colour
black
grid colour
dark grey
first 5 series colours
red, blue, green, purple, orange


|index|
addDataSeries (type, option, data, legend)
  type 'C' = column, 'L' = line, 'P' = Pie
  option

0 or 1 for column types. Setting any column type option value to '1' stacks all columns.

For line types values 0 - 5 indicate the marker type (None, +, x, circle, square, diamond). Negative values draw the markers only.

The following constants have been defined
  • LINE_MARK_NONE
  • LINE_MARK_PLUS
  • LINE_MARK_X
  • LINE_MARK_CIRCLE
  • LINE_MARK_SQUARE
  • LINE_MARK_DIAMOND

For pie charts the options sets the labelling of the segments and showing values and percentages in the legend

The following constants are defined and can be added in various combinations. PIE_CHART_PCENT and PIE_CHART_VALUE are mutually exclusive. (PCENT takes priority if both used)
  • PIE_NONE
  • PIE_LEGEND_PCENT (1)
  • PIE_LEGEND_VALUE (2)
  • PIE_CHART_VALUE (4)
  • PIE_CHART_PCENT (8)
  data The data values to be plotted. Can be either an array or a comma-delimited string of values
  legend The series legend. If legends are specified, the right margin size is recalculated to accommodate the legends
   


You can add as many series as you want. Series above the 5th will be plotted with white colour unless a colour is specified with setSeriesColor

Series are drawn in the same order as they were added

Each P type series is a wedge of a pie chart. If a P type series is found then the chart is a pie chart and only P-series will be plotted. If the data for a P-series has more than one value, the data is summed.



|index|
drawGraph ([filename])
  filename [optional] if specified the image will also be saved to the file
   


Draw and sends the image (.png) to the browser then exits. Optionally writes the image to a specified file



|index|
setBgColor (red,green,blue [,transparent])
  red, green, blue colour components of the image background colour
  transparent optional - 0 or 1. If 1, the background area around the chart becomes transparent. Default is 0.


|index|
setChartBgColor(red,green,blue [,asBackground])
  red, green, blue colour components of the chart area background colour
  asBackground 0 or 1. If 1, sets the chart background to the image background and the red,green, blue values are ignored. If the image background is transparent then the chart background will be too.
   


Setting the chart background colour gives a monochrome background to the chart area with no banding.



|index|
setChartBgColor2 (red,green,blue)
  red, green, blue colour components of the chart area second background colour
   
Call to set the second colour if banding of the chart background is wanted.


|index|
setGridColor (red,green,blue)
  red, green, blue colour components of the chart grid colour


|index|
setMargins (left, top, right, bottom)
  left, top, right, bottom value in pixels for each of the margins
   
Setting a value to 0 leaves that margin unchanged. Note that the right margin will be automatically adjusted to accommodate the legend


|index|
setBgImagePos (left, top)
  left, top x and y coordinates of the top-left of the placed image
   
By default, a background image is centered in the chart if the image size is smaller than the chart and background image mode is 'clipped'


|index|
setBgImageAlpha (transparency)
  transparency a value from 0 to 100. (0=transparent, 100=opaque)
   
Use to fade the background image


|index|
setSeriesColor (series,red,green,blue)
  series the number of the series (starting at 1) to be changed
  red, green, blue colour components of the chart series plot colour
   
Default colours are set only for the first five series


|index|
setTextColor (red,green,blue)
  red, green, blue colour components of the chart text colour
   
Used for titles, axis labels, legends


|index|
setTitle (title, subtitle)
  title The chart title
  subtitle Chart subtitle


|index|
setXAxis (title, grid)
  title The x axis title
  grid 0 = no grid lines, 1 = gridlines
   
Not required for pie charts


|index|
setXLabels (labels)
  labels The labels for x axis values. Can be an array or a comma-delimited string
   

If any of the data series has more values than there are labels, additional labels 'A', 'B' etc are generated

Not required for pie charts



|index|
setYAxis (title, min, max, interval, grid)
  title The y axis title
  min The y axis minimum value
  max The y axis maximum value
  interval The y axis value between grid lines
  grid 0 = no grid lines, 1 = gridlines
   

If data in any series are above or below the min and max specified the min and max will be altered to match the data and the interval set to the total range divided by 4

Not required for pie charts



|index|
Code samples and output
	include('baaChart.php');
	$mygraph = new baaChart(600);
	$mygraph->setTitle('Regional Sales','Jan - Jun 2002');
	$mygraph->addDataSeries('P',PIE_CHART_PCENT + PIE_LEGEND_VALUE,"25,30,35,40,30,35","South");
	$mygraph->addDataSeries('P',PIE_CHART_PCENT + PIE_LEGEND_VALUE,"65,70,80,90,75,48","North");
	$mygraph->addDataSeries('P',PIE_CHART_PCENT + PIE_LEGEND_VALUE,"12,18,25,20,22,30","West");
	$mygraph->addDataSeries('P',PIE_CHART_PCENT + PIE_LEGEND_VALUE,"50,60,75,80,60,75","East");
	$mygraph->addDataSeries('P',PIE_CHART_PCENT + PIE_LEGEND_VALUE,"30,45,50,55,52,60","Europe");
	$mygraph->drawGraph();

	include('baaChart.php');
	$mygraph = new baaChart(600);
	$mygraph->setTitle('Regional Sales','Jan - Jun 2002');
	$mygraph->setXLabels("Jan,Feb,Mar,Apr,May,Jun");
	$mygraph->addDataSeries('L',LINE_MARK_X,"25,30,35,40,30,35","South");
	$mygraph->addDataSeries('L',LINE_MARK_CIRCLE,"65,70,80,90,75,48","North");
	$mygraph->addDataSeries('L',LINE_MARK_SQUARE,"12,18,25,20,22,30","West");
	$mygraph->addDataSeries('L',LINE_MARK_DIAMOND,"50,60,75,80,60,75","East");
	$mygraph->addDataSeries('L',LINE_MARK_NONE,"30,45,50,55,52,60","Europe");
	$mygraph->setBgColor(255,255,255,1); //Transparent
	$mygraph->setXAxis("Month",1);
	$mygraph->setYAxis("Sales (£000)",0,100,10,0);
	$mygraph->drawGraph();

	include('baaChart.php');
	$mygraph = new baaChart(600);
	$mygraph->setTitle('Regional Sales','Jan - Jun 2002');
	$mygraph->setXLabels("Jan,Feb,Mar,Apr,May,Jun");
	$mygraph->addDataSeries('C',COLS_STACKED,"25,30,35,40,30,35","South");
	$mygraph->addDataSeries('C',0,"65,70,80,90,75,48","North");
	$mygraph->addDataSeries('C',0,"12,18,25,20,22,30","West");
	$mygraph->addDataSeries('C',0,"50,60,75,80,60,75","East");
	$mygraph->addDataSeries('L',3,"30,45,50,55,52,60","Europe");
	$mygraph->setBgColor(0,0,0,1);  //transparent background
	$mygraph->setChartBgColor(0,0,0,1);  //as background
	$mygraph->setXAxis("Month",1);
	$mygraph->setYAxis("Sales (£000)",0,250,50,1);
	$mygraph->drawGraph();