Chart Helper
The Chart Helper file contains functions that assist in working with the bundled Flash charts. The author of HerbIgniter purchased a Developer's License, and has included it in this library under this library's license. If you want the source code and a license of your own, visit amCharts.
Loading this Helper
This helper is loaded using the following code:
$this->load->helper('chart');
The following functions are available:
pie( $settings, $labels, $slices, filename="output.xml", w=534, h=170, align="middle", bg="transparent", path=NULL, chart_title=NULL )
Deploys the amCharts Pie Chart. There are a lot of settings. Default settings are filled in if you don't set all of them.
You can read about the settings by looking at the Chart Helper file in the HerbIgniter source code.
You can also visit amCharts, but our interface doesn't follow those completely (due to the fact that we are in an array and they are in XML). You must define a writeable (chmod 777) xml dump file, which programs the actual Flash chart on the page. The path parameter sets the required path for the swf file. If it is not set, it defaults to the httproot/charts. You must also populate data via the slices parameter with a specific object (shown below, after a long list of settings). You can also program the labels parameter.
This function has a lot of settings:
- <settings> (these settings are common to all charts)
$settings['font'] font name
$settings['size'] font size
$settings['color'] font color
$settings['decimal'] decimal seperator
$settings['thousands'] thousands seperator
$settings['digits'] digits to be shown after decimal to right
$settings['max'] maximum value for chart data item
$settings['min'] minimum value for chart data item
$settings['polldelays'] number of seconds between data polls to xml source
$settings['preload'] true/false - display preloaded data
$settings['redraw'] true/false - redraw when zoomed / resized
$settings['timestamp'] true/false - store a timestamp
$settings['precision'] how many numbers shown after comma for calculated values (percents)
$settings['exclude'] true/false - to exclude invisible slices when alpha=0 when calculating percents
$settings['js'] true/false - polls javascript for signals
- <pie>
$settings['x'] size of pie
$settings['y'] size of pie
$settings['radius'] radius of pie chart
$settings['inner_radius'] inner radius for hole in donut chart (or set to 0)
$settings['height'] pie height used by 3d effect
$settings['angle'] pie leaning angle used by 3d effect
$settings['start_angle'] angle of the first slice, works properly only when height=0; when height>0, valid entries are 90, 270
$settings['outline'] outline color
$settings['outline_alpha'] outline opacity (percentage)
$settings['base_color'] color of first slice
$setting['brightness'] (-100% to 100%) brightness where 0=no change, negative means darker, positive means lighter
$settings['colors'] a list of colors for each slice, example: #00000F,#0D8ECF,...
$settings['target'] _blank, _top, _parent, etc
$settings['alpha'] opacity of chart
$settings['hover'] mouse hover brightness, -255 to 255
$settings['gradient'] 'linear' or 'radial'
$settings['ratio'] number list (-255 to 255 each) separated by commas for gradiant
$settings['fly'] number in seconds of flying animation
$settings['flyeffect'] 'bounce', 'regular', 'strong'
$settings['flyradius'] percentage radius used during animation
$settings['flyalpha'] alpha
$settings['sequenced'] true/false - whether the slices appear together or in sequence
$settings['pull'] true/false - are slices 'pulled' from the chart?
$settings['pulltime'] number in seconds of pulling animation
$settings['pullfx'] 'bounce', 'regular', 'strong'
$settings['pullradius'] number (percentage) how far the slices should be pulled out
$settings['pull1'] true/false - slices are pulled exclusively, rather than toggled in/out on click
$settings['labelradius'] percentage/pixels - distance of the labels from the pie
$settings['textcolor'] hex color code of label text (defaults to master text color)
$settings['textsize'] size of label text (defaults to master text size, above)
$settings['width'] label width
$settings['lines'] true/false - show lines from slices to data labels?
$settings['line_color'] color of the lines
$settings['line_alpha'] opacity of the lines
$settings['hide'] data labels of slices less than this percentage will be hidden
$settings['avoid'] true/false - when true, labels are arranged so they do not overlap
$settings['group'] a percentage threshold where values < this are 'grouped' into a single slice
$settings['groupcolor'] color of the 'group' slice
$settings['grouptitle'] title of the 'group' slice
$settings['groupurl'] url of the 'group' slice
$settings ['groupdesc'] text description of the group
$settings['grouppull'] true/false - can this slice be removed from the pie?
$settings['bgcolor'] background color
$settings['bgalpha'] background opacity
$settings['border_color'] border color
$settings['border_alpha'] border opacity
$settings['bgimage'] background image: swf, jpg (non progressive-scan), gif
$settings['balloon'] true/false - enables the rollover-balloon label
$settings['balloon_color'] balloon background color
$settings['balloon_alpha'] balloon opacity
$settings['balloon_text'] balloon text color
$settings['balloon_size'] balloon size
$settings['balloon_width'] balloon width
$settings['balloon_corner'] balloon corner radius
$settings['balloon_border_width'] balloon border width
$settings['balloon_border_alpha'] balloon border alpha
$settings['balloon_border_color'] balloon border color
$settings['balloon_format'] {value} {title} {percents} {description}) You can format any data label: {value} - will be replaced with value and so on. You can add your own text or html code too.
- <legend>
$settings['legend'] true/false - activate chart legend
$settings['legend_x'] top left x of legend
$settings['legend_y'] top left y of legend
$settings['legend_width'] width of legend
$settings['legend_color'] color of legend
$settings['max_columns'] maximum number of columns in the legend
$settings['legend_alpha'] opacity of the legend
$settings['legend_border_color'] border color of the legend
$settings['legend_border_alpha'] border opacity of the legend
$settings['legend_text'] text color of the legend
$settings['legend_size'] text size of the legend
$settings['legend_spacing'] legend spacing (vertical and horizontal gap between entries)
$settings['legend_margins'] legend margin
$settings['legend_reverse'] true/false - when true, sort in reverse order
$settings['legend_align'] 'left', 'center', 'right' - <keys>
$settings['key_size'] size of the key
$settings['key_border_color'] border color (leave as '' for no border)
$settings['key_values'] true/false - show values near legend entries?
$settings['key_width']
$settings['key_format'] content, using {value} and {percents} to designate locations
- <export settings>
$settings['export'] true/false - allow exporting of chart image
$settings['export_target'] where to place it / file name
$settings['export_x'] x upper left of exporting message
$settings['export_y'] y upper left of exporting message
$settings['export_bgcolor'] background color of exporting message
$settings['export_alpha'] opacity of exporting message
$settings['export_color'] exporting message font color
$settings['export_size'] exporting message font size
$settings['errors'] true/false - show error messages?
$settings['error_x'] x location upper left of error message
$settings['error_y'] y location upper left of error message
$settings['error_color'] background color of error message
$settings['error_alpha'] opacity of error messages
$settings['error_text'] font used by error messages
$settings['error_size'] size of font used by error messages
$settings['strings_error'] what to report when there is no data available
$settings['strings_export'] what to report when there is an exporting error
$settings['strings_collecting'] what to report when there is an error collecting polled data
$settings['menu_definitions'] a set of xml declarations that look like: <menu function_name="printChart" title="Print chart"></menu>
$settings['menu_zoom'] true/false - show flash player zoom menu
$settings['menu_print'] true/false - show print option
- <labels>
$label['lid'] label id
$label['x'] label's x location (upper left)
$label['y'] label's y location (upper left)
$label['rotate'] label's rotation 0-360
$label['width'] label's maximum width
$label['align'] label's alignment
$label['color'] label's font color
$label['size'] label's font size
$label['text'] label text: supports <b>, <i>, <u>, <font>, <a href="">, <br/>
- $settings['messages']; additional messages sent via xml of the form: <message>content</message>
- <slices>
$slice['title']
$slice['pullout']
$slice['value']
$slice['url']
Example:
$slices = array(
array( 'title'=>'Percentage of Herb Growers', 'pullout'=>true, 'value'=>17, 'url=>'http://www.potgrowersusa.com' ),
array( 'title'=>'Percentage of Herb Consumers, 'pullout'=>true, 'value'=>35, 'url=>'http://www.hightimes.com' ),
array( 'title'=>'Percentage of Herb Drinkers', 'pullout'=>true, 'value'=>70, 'url=>'http://www.moderndrunkard.com' )
);
$settings = array( 'base_color'=>'FF0000' );
$page->append_body( pie( $settings, $slices, "somewriteable.xml" ) );
function column_chart( settings, labels, guides, graphs, data, series='1',
filename="output.xml", w=534, h=170, align="middle", bg="transparent",
path=NULL, chart_title=NULL )
You can also invoke this function using the synonymous bar() function. There are a lot of settings. In fact, this is the most complex of the amCharts (except for perhaps the Stock Chart called amStock). Default settings are filled in if you don't set all of them.
You can read about all of the settings by looking at the Chart Helper file in the HerbIgniter source code.
You can also visit amCharts, but our interface doesn't follow those completely (due to the fact that we are in an array and they are in XML). You must define a writeable (chmod 777) xml dump file, which programs the actual Flash chart on the page. The path parameter sets the required path for the swf file. If it is not set, it defaults to the httproot/charts. You must also populate data via the slices parameter with a specific object (shown below, after a long list of settings). You can also program the labels parameter.
Usage example:
$slices = array(
array( 'title'=>'Percentage of Herb Growers', 'pullout'=>true, 'value'=>17, 'url=>'http://www.potgrowersusa.com' ),
array( 'title'=>'Percentage of Herb Consumers, 'pullout'=>true, 'value'=>35, 'url=>'http://www.hightimes.com' ),
array( 'title'=>'Percentage of Herb Drinkers', 'pullout'=>true, 'value'=>70, 'url=>'http://www.moderndrunkard.com' )
);
$settings = array( 'base_color'=>'FF0000' );
$page->append_body( bar( $settings, $slices, "somewriteable.xml" ) );