Extension:PChart4mw

This 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 the charts. It allows for 2- or 3-dimensional charts, which are all within the potential of the pChart library. The charts 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. To enable full flexibility and full integration with other extensions pchart4mw supports both the standard MediaWiki tag syntax and the parser function syntax.

Use
pchart4mw has a unique tag or function for each chart type it supports. It can be used with its tags or with its parser functions.

The tag method is the traditional way of adding extra functionality to MediaWiki. The parser function method is added to pChart4mw as of version 1.1. Use the parser function method to integrate pchart4mw's charting capabilities with other MediaWiki functions or extensions.

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

Installation and configuration
These samples got you interested in the extension? Its installation is very straight forward. Here's how to do it:

Installation
This installation describes the basic pchart4mw installation using its default settings.

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

$IP/extensions/pChart4mw

You shoud have the following files and folders after installation: $IP/extensions/pChart4mw/colorschemes/ /colorschemes/*.txt /fonts/ /fonts/*.ttf /pChart/ /pChart/*.class /pChart4mw.php /pChart4mw.class.php /pChart4mw.bars.class.php /pChart4mw.bubble.class.php /pChart4mw.lines.class.php /pChart4mw.pie.class.php /pChart4mw.radar.php /pChart4mw.scatter.class.php /library.inc.php /0-changes.txt /0-licence.txt Note: Check the system requirements for pChart4mw, your PHP installation needs to have GD library with freetype extension enabled.

Configuration
To configure this extension a few parameters need to be set.

Add the following line to the file LocalSettings.php
 * Tell MediaWiki about this extension

The cache directory is the folder where the chart images are saved. The chart image file is loaded on the page to be shown. When pchart4mw's cache option is enabled (this is default), the chart image file is created only once. This saves server processing time when a page is loaded. If anything in the chart's code or data is changed, a new file is created. The default cache directory is:
 * Cache directory

$IP/images/pChart4mw

The cache directory must exist and be writeable! Check, and if necessary set, the write permissions. Also read the maintenance instructions of the cache directory.

Note that pchart4mw has several settings to customize its installation and its behaviour to your preferences. The above default installation (choice of folders) and configuration can be modified. For more configuration options and preference settings visit the pchart4mw project site.
 * More optional settings

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 or   function for the graph of your choice. pchart4mw receives a call every time a wiki page with a pchat4mw tag or function is viewed by a user
 * pchart4mw receives the full text from the call between start and end tag
 * From this full text the unique graph image filename is determined (e.g. )
 * pchart4mw processes the chart definition and the data
 * pchart4mw uses the pChart Library to create an image of the chart
 * pchart4mw uses a cache folder, (default ), 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 folder is: ). The file names 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 (when a user edits the chart definition and/or the data) the file name of the created image also changes.

A file name 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 clean-up in this folder. It is recommended to delete all the files in this cache folder once in a while. Graph images will be (re)created automatically 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 this pChart library produces are a great addition in charting functionality for MediaWiki.

The design of pchart4mw is partly inspired by extensions "gchart4mw" and "gnuplotBasic". (note that neither one of them are actively maintained anymore).

Its development
Its development started early 2009. It was first publicly released in July 2009. As of November 2009 its full documentation was finished on the pchart4mw project site. As of version 1.1 - released in June 2010 - pchart4mw supports parser functions to enable integrating pchart4mw's charting capabilities with other MediaWiki functions or extensions.

This extension is developed and tested with pChart 1.27d, MediaWiki 1.12+ 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 only go as far as what the pChart library provides.
 * No data files, inline data only. pchart4mw only accepts data that is part of the wiki markup.
 * Unique tag and function 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.
 * Support both tag syntax and parser function syntax for full flexibility and integration with other extensions.

Its security
All the data in the wiki page is processed on the MediaWiki server environment by this extension and the installed pChart library. It does not use any online service, 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 (4) use with MediaWiki (mw) (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.

Talk and share
Please use the talk page for talking about or sharing on pchart4mw.