TeeChart and CodeIgniter

Derek Jones edited this page Jul 5, 2012 · 10 revisions
Clone this wiki locally

Category:Library | Category:Library::External | Category:Library::Charts | Category:Charts


TeeChart for PHP can be used as a library for CodeIgniter. It allows you to setup a Chart with with a few lines of

code the easy way. This library includes many Chart styles, Functions, Tools and lot of features which makes it very


Don't forget to check the Online Demo from

our web site.

You can also download the Eval version.


GD Library. PHP5 or above.


Please check all the Features


1) Download TeeChart for PHP and copy the contents of the “source” folder to the “system/libraries/teechart” directory. If you're using the Eval version you will need to download the PHPExpress loaders, copy them into the webroot folder and set as an extension. You can find detailed instructions in the Install.txt file (included with the zip installer). 2) Create a directory “temp” in your document root (same directory as your index.php) to store the generated charts. Make sure this directory is writable by Apache. 3) If you use mod_rewrite, add the “temp” directory to your .htaccess exclusion list.

Example of use


Create a new Controller called "teechart" which will be used to load the TeeChart library, to setup the Chart and load the view.


class TeeChart extends Controller {

    function TeeChart()

    function index()
        $data['title'] = "Using TeeChart from CodeIgniter";        
        // Setup Chart
        // The Data could com from a function defined into the model, which could be adquired 
        // from a database.
        $ydata = array(20,20,20,20,20);   
        $labels = array('Cars','Phones','Bikes','Computers','Motorbikes');        
        $chart = new TChart(500,350);
        $chart->getChart()->getHeader()->setText("Pie Style");
        $chart->getChart()->getAspect()-> setChart3DPercent(35);

        // Here we use the Pie Style, but TeeChart includes many Series types (like Bar, 
        // HorizBar, Line, HorizLine, Area, HorizArea, Candle, Volume, etc.. ). Check them !
        $pie=new Pie($chart->getChart());
        ThemesList::applyTheme($chart->getChart(),1);  // BlackIsBack 
        // Setup the Pie

        // File locations
        // Could possibly add to config file if necessary
        // In the webroot (add directory to .htaccess exclude)
        $chart_temp_directory = 'temp';  
        // Create the Chart and write to file 
        $chart->render($chart_temp_directory . '/' . 'chart.png');    
        $data['chart'] = $chart_temp_directory . '/' . 'chart.png';
        $this->load->view('chart_view', $data);        


Now we just have to create the view called "chart_view" which will output the generated file.

<style type="text/css">

body {
 background-color: #fff;
 margin: 40px;
 font-family: Lucida Grande, Verdana, Sans-serif;
 font-size: 14px;
 color: #4F5155;

h2 {
 color: #444;
 background-color: transparent;
 border-bottom: 1px solid #D0D0D0;
 font-size: 16px;
 font-weight: bold;
 margin: 24px 0 2px 0;
 padding: 5px 0 6px 0;

<title><?php echo $title?></title>
<h2>&lt;?php echo $title;?&gt;</h2>
<img src="&lt;?php echo  base_url(). $chart?&gt;"/>


That’s it! On my configuration, I run the file as http://mysite/chart.



File:TeeChartAndCodeIgniter.zip contains the example files.

Enjoy with TeeChart for PHP ! Steema Software