Extension:PChart4mw

Purpose
The PHP Chart for MediaWiki extension (pchart4mw) allows you to visualize your data with charts like line-, bar-, pie-, radar-, scatter- and bubble charts. It uses the (free) PHP Chart library pChart to produce these graphs. It allows for 2- or 3-dimensional graphs, which are all within the potential of the pChart library. The graphs are based on your data from the wiki page.

pchart4mw works, together with the pChart library, fully within your MediaWiki Server environment. The data is processed completely within the server environment.

Use
Structure of a pchart4mw call is:  data... 


 * With    you define the chart type you want. Possible values are:
 *   for bar charts
 *   for pie charts
 *   for line charts
 *   for scatter diagrams
 *   for radar charts
 *  </tt> for bubble charts
 * Parameters p1 p2 p3 ...</tt> can be added within the charttype tag to customize the chart. Note that the parameters are separated by a space, and they can be written on multiple lines for readability. Visit the pchart4mw project site for details on parameters.
 * The  data... </tt> is comma separated on multiple lines

Sample charts
Here are some simple samples of what you can do with pChart for MediaWiki:

Installation and configuration
Got you interested in these samples? Its installation is very straight forward. Here's how to do it:

Installation

 * Install the pChart library
 * The first thing you need is a copy of the pChart library. Download the latest version from the pChart website . Follow the instructions for pChart installation. The location where pChart is installed must be specified later on in LocalSettings.php</tt>. Remember this location. Check the system requirements for the pChart library, your PHP installation needs to have GD library with freetype extension enabled.
 * Possible locations for the pChart library are, for example:
 * Option 1: pChart library installed in [documentroot]/pChart/pChart.class</tt>
 * Option 2: pChart library installed in $IP/extensions/pChart4mw/pChart/pChart.class</tt> (sub-directory of pchart4mw extension)


 * Install this extension
 * Download the pchart4mw extension from the pchart4mw site and save in the directory


 * $IP/extensions/pChart4mw

Configuration
To configure this extension, several parameters need to be set. A few options are needed for the extension to function properly. Other settings are optional:


 * Tell MediaWiki about this extension
 * Add the following line to the file LocalSettings.php
 * require_once( "$IP/extensions/pChart4mw/pChart4mw.php" );


 * Set pChart library location
 * Defines the location where the pChart library is installed. The variable $wgPChart4mwPChartPath</tt> contains the absolute path to the directory where the pChart class resides. Add the following line to LocalSettings.php


 * Option 1: pChart library installed in [documentroot]/pchart/pChart.class</tt>
 * $wgPChart4mwPChartPath = $_SERVER["DOCUMENT_ROOT"] . "/pChart";
 * Option 2: pChart library installed in $IP/extensions/pChart4mw/pChart/pChart.class</tt> (sub-folder of pchart4mw extension)
 * $wgPChart4mwPChartPath = $_SERVER["DOCUMENT_ROOT"] . "/wiki/extensions/pChart4mw/pChart";


 * Set pChart font location (optional)
 * Determines the truetype font file to write text into the graph. This variable contains the absolute path to the .ttf</tt> file. The pChart installation contains some font files by default in the Fonts</tt> subdirectory. Add the following line to LocalSettings.php:
 * $wgPChart4mwFont = $wgPChart4mwPChartPath . "/Fonts/tahoma.ttf";
 * to use the tahoma.ttf font from the Fonts subdirectory in the pChart directory.


 * Set cache directory (optional)
 * Directory where the created images are saved. The images are saved to this directory when created, and the saved file is loaded on the page where it should be shown. When the cache is enabled, the file is created only once, saving a lot of processing time when a page is loaded frequently. If anything in the chart code is changed, a new file is created. When the cache is disabled, the file is created again every time a page is loaded.
 * The directory must be specified as a subdirectory of the $wgUploadPath</tt> directory. The directory must exist and be writable. By default, the cache directory is $wgUploadPath/pChart4mw</tt> ([wiki]/images/pChart4mw</tt>).
 * Add the following line to LocalSettings.php
 * $wgPChart4mwCacheDir = "pChart4mw";


 * More optional settings
 * For more (optional) configuration options and default settings visit the pchart4mw project site.

How does pchart4mw work?
As a wiki author you create a chart definition within a wiki page. To do this you type simple chart syntax plus the data to be displayed in the chart. pchart4mw processes your chart definition and uses the pChart library to create a chart image. Browsing the wiki page you get your chart image displayed.

Figure 1 gives a simplified overview of the working of pchart4mw. In more detail:
 * A pchart4mw call is initiated from a wiki page written in wiki markup. A call starts with the  start tag of the graph of your choice. pchart4mw receives a call every time a wiki page with this tag is viewed by a user
 * pchart4mw receives the full text from the call between start end end tag
 * From this full text the unique graph image filename is determined (e.g. )
 * pchart4mw uses the pChart Library to create an image of the chart
 * pchart4mw uses a cache folder, (default images/pchart4mw</tt>), to store the image file.
 * If the graph image already exists in the cache folder, pchart4mw doesn't create it again. If it doesn't exist pchart4mw creates it.
 * The graph image (e.g. ) is then shown on the page.

Maintenance of your site
As described in 'how does pchart4mw work', pchart4mw stores chart images in the cache folder (default ). The filenames of these images are automatically generated based on the full content of the pchart4mw call. This means that every time the content of a call changes the filename of the created image also changes.

A filename is for example:

The consequence is that over time the cache folder becomes populated with unused (orphan) graph images. Periodically the wiki site administrator should do some cleanup in this folder. It is recommended to delete all the files in this directory once in a while. Graph images will be (re)created whenever a page is viewed and pchart4mw discovers the graph image doesn't exist.

Its origin
The creation of this extension was inspired after discovering the excellent PHP Chart library pChart on the internet. The stunning charts the pChart library produces are a great extension to be able to make charts for MediaWiki.

The design of pchart4mw is partly inspired by extensions gchart4mw (Google chart for Mediawiki) and gnuplotBasic.

Its development
This extension is developed and tested with pChart 1.27d, MediaWiki 1.13+ and PHP 5.2 on a Windows machine. It should work just as fine on other versions/platforms, as long as PHP 5.x is used with GD Library and freetype extension enabled.

Its design choices
The design choices made for pchart4mw.
 * Use of pChart library to create the graphs. This extensions options go as far as what this library provides.
 * No files, inline data only. pchart4mw only accepts data that is part of the wiki markup.
 * Unique tag for every chart type. This helps keep the syntax as simple and uniform as possible.
 * Simple user syntax. The syntax is kept as simple as possible to make this extension usable for a wide variety of users.

Its security
All the data in the wiki page is processed on the MediaWiki server environment by this extension and the installed pChart library. Your data does not have to be sent elsewhere.

Its name
It is called pchart4mw because:
 * It is based on the PHP Chart library (pChart) and it is made for use with MediaWiki (although this extension could be easily be adjusted for another php based wiki)

More on pchart4mw...
Please note that this page is only a brief introduction to pchart4mw. Visit the pchart4mw project site for more details and full documentation.