Innovative Computer Solutions,
Development & Technical Support

07975 997026 • enquiries[delete-me]@[delete-me]

User Tools

Site Tools


hArpanet jpGraph Library

A CI Library has been created (in /application/libraries) named jpgraph.php

The CI jpGraph Library has been created as a single interface to jpGraph and to establish some level of consistency in jpGraph use within Trostre Intranet systems. It does not need to be used - you can work directly with the jpGraph application if preferred (see

This library is useful in the current (Feb 2013) Trostre Apache/PHP server environment because the jpGraph library is 'located somewhere on the server' (see below) rather than sitting within the CI /application/libraries/jpgraph folder. If jpGraph was located in the latter location, it could simply be loaded using standard CI methods. eg. $this→load→library('jpgraph');

jpGraph Library

jpGraph library files are located in /usr/share/jpgraph

Image Cache

All graphs are created as image files within the jpGraph cache folder.


The jpGraph cache path used to store cached graph images must be set within the /application/config/tata.php configuration file.

This location must be publicly accessible as your View files need to display the images in the client browser.

   * set location to store jpgraph images
  $config['jpgraph_imgpath'] = './assets/img/jpgraph_cache/';

Cache Filenames

Each graph generated in the cache will have a 'hashed' filename based on the URI from which it is generated PLUS a unique ID for the image.

  • The URI is added automatically
  • The unique ID must be set from within your controller. It should be based on values related to the requested graph. eg. A graph of 12 months for year 2013 could be given an ID of '20130112'. This ensures that the cache folder doesn't fill up with multiple files containing the same graph.

Initialising CI jpGraph Library

To initialise the CI jpGraph Library within your controller method, use …

  $jpgraph = & $this->jpgraph;

Note: In the above example, the jpGraph library has been aliased 'by reference' to $jpgraph to simplify use within the controller. Using this approach, you can use $jpgraph→setting instead of $this→jpgraph→setting.

Using CI jpGraph Library

Once the CI jpGraph Library has been loaded, you need to:

  • Set the x,y size of the graph. Note: This is not required if you want a default graph of 640×480.
  $jpgraph->graph_size = array(800,600);
  • Pass the relevant values to the required graph type (eg. 'barchart') and get a retrieve the graph object
  $ydata = array(10,50,23,79,85,60,12,42,37);
  $graph = $jpgraph->barchart($ydata, 'TESTING');
  • Call make_png() to generate the cache file and retrieve the filename
  $png = $jpgraph->make_png( $graph, '2013012' );
  • Pass the filename to your View
  tplSet('bodyContentBottom', "<img src='$png'>");

Note: This example uses the hArpanet Template System tplSet() method as implemented by Trostre Intranet systems.



  • Display a thermometer graph (with multiple expansion tubes if required)
programming/php/codeigniter/jpgraph/index.txt · Last modified: 15/06/2013 16:31 (external edit)