I was looking for a small yet capable charting library to use in a CodeIgniter project.
There are excellent libraries available, notably jpgraph and chartdirector. Unfortunately they are large
and complex and also have restrictive licenses.
I came across Panachart by accident and it is perfectly adequate for my needs; also, adapting the code
to provide it as a library for CodeIgniter proved almost trivial.
That said, Panachart is not perfect, the current version (0.9.2) has some annoying bugs, the code to add Legends
to charts does not work, and there are only a few plot types supported [Pie charts are NOT supported as yet]
On the bright side, code has been provided on the Panachart sourceforge project which squashes most of the bugs,
and adds rudimentary Legend handling.
Most important, the demo (0.9.3) version running on the Panachart website appears to
have added proper Legend handling, fixed the bugs and added numerous nifty plot types such as spline, bubble and error.
Using the library in your own CI application is simple.
Please Note: Application Library loading differs between CodeIgniter versions 1.4.x and 1.5.0
Version 1.5.0 : Application libraries are automatically initialised, so NO init_ files are needed.
Unzip the Panaci.zip file into a temporary folder on your hard drive.
CI Version 1.4.x :
Copy the file /ci_1.4/Chart.php to your own applications libraries folder.
Copy the file /ci_1.4/init_chart.php to your own applications init folder.
CI Version 1.5.x :
Copy the file /ci_1.5/Chart.php to your own applications libraries folder.
That's it!
To use it in your own application, just load the library chart in your controller.
Remember to pass the library an array variable, params, which will set the default width, height, margin and background.
Create a function in your controller to set up the chart and feed it data points.
Call the library plot() method to output the chart image, either to a file or http stream.
You can display the image file in your application views with the img tag.
Examples of usage are found here
If you need to see a working example in a CodeIgniter application, files are provided.
Unzip the Panaci.zip to a temporary folder on your hard drive.
Create a test application folder in your webserver document folder.
Copy the required CodeIgniter files, using the standard CI layout.
CI Version 1.4.x
Copy the file /ci_1.4/Chart.php to your test application libraries folder.
Copy the file /ci_1.4/init_chart.php to your test application init folder.
CI Version 1.5.0
Copy the file /ci_1.5/Chart.php to your test application libraries folder.
Copy the file welcome.php to your test application controllers folder.
Copy the contents of the view folder to your test application views folder.
Create a folder called images under your test application root.
The images folder must have write permissions.
You should have a layout something like this:
-- chart_test
-- images
-- system
-- application
-- controllers
- welcome.php
-- init
- init_chart.php
-- libraries
- Chart.php
-- views
- welcome_message.php
- documentation.php
- examples.php
- graph.php
- graph_display.php
Edit your test application config file to point to the test application.
Point your Browser at the location of your test application on your web server,
this might commonly be something like
http://localhost/chart_testYou should see a web page heading : A Charting Library for etc etc...
Class METHODS
[object] chart($width, $height, $margin, $background) - constructor
$width Chart's image width
$height Chart's image height
$margin Left/top/right/bottom margin
$backgroundColor Background color
[void] setFormat($numberOfDecimals, $thousandsSeparator, $decimalSeparator) - set values format
$numberOfDecimals
$thousandsSeparator
$decimalSeparator
[void] setTitle($title, $textColor, $font) - set the title of the chart
$title Chart's title
$textColor Chart's title color ["#FFFFFF"]
$font Title font size [1,2,3,4,5]
[void] setPlotArea($style, $strokeColor, $fillColor) - set plot area attributes
$style Plot area border style [SOLID,DASHED,DOTTED,
MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$strokeColor Border color ["#FFFFFF"]
$fillColor Plot area background color ["#FFFFFF"]
[void] setXAxis($color, $style, $font, $title)
$values Axis Y color ["#FFFFFF"]
$style Axis X stroke style [SOLID,DASHED,DOTTED,
MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$font X title font [1,2,3,4,5]
$title X axis title
[void] setYAxis($color, $style, $font, $title)
$color Axis Y color ["#FFFFFF"]
$style Axis Y stroke style [SOLID,DASHED,DOTTED,
MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$font Y title font [1,2,3,4,5]
$title Y axis title
[void] setGrid($colorHorizontal, $styleHorizontal, $colorVertical, $styleVertical) - set grid attributes
$colorHorizontal Grid's horizontal lines color ["#FFFFFF"]. If empty string, the H lines will not be plotted
$styleHorizontal Grid's horizontal lines style
[SOLID,DASHED,DOTTED, MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$colorVertical Grid's vertical lines color ["#FFFFFF"]. If empty string, the V lines will not be plotted
$styleVertical Grid's vertical lines style
[SOLID,DASHED,DOTTED, MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
[void] addSeries(&$values, $plotType, $title, $style, $strokeColor, $fillColor) - add a new series to the chart
$values Array of values
$plotType Plot type ["bar", "line", "dot", "area", "step" or "impuls"]
$title Series title
$style Stroke style [SOLID,DASHED,DOTTED,
MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED,
LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$strokeColor Stroke drawing color of the series (lines)
$fillColor Fill drawing color of the series
[void] setLabels(&$labels, $textColor, $textFont, $direction)
$arrayLabels Array of labels
$textColor Text color of the axis labels
$textFont Font size of the axis labels
$direction X labels direction. [HORIZONTAL, VERTICAL]
[void] plot($file) - plot the chart to a file
$file File path to store image (if "" image will be output to STD)
NB!! Version 0.9.2 of Panachart does not have a working Legend function.
This library uses a patched version with a working Legend function by Emilio Veloso.
Future versions of Panachart may have different parameters to the Legend function.
end NB!!
[void] setLegend($style, $strokeColor, $fillcolor, $font)
$style [SOLID,DASHED,DOTTED, MEDIUM_SOLID,MEDIUM_DASHED,MEDIUM_DOTTED, LARGE_SOLID,LARGE_DASHED,LARGE_DOTTED]
$strokeColor Stroke drawing color of the legend box
$fillColor Stroke drawing color of the legend box
$font Legend text font [1,2,3,4,5]