Skip to content

A PHP Class for FusionChart that assigns attributes the PHP way and can be printed into the correct JSON string for use to be parse by a Javascript file or printing to the PHP page

Notifications You must be signed in to change notification settings

qthen/FusionChart-PHP-Class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 

Repository files navigation

PHP class for FusionCharts that can:

  • Be assigned FusionChart attributes the PHP way
  • No need to manage or manually concanetenate a JSON string for creating a graph
  • Can echo'd out into the correct FusionChart JSON string
  • Can be used for parsing by a Javascript file such as (HTTP POST request) after being printed or used to PHP display

The class was tested for line charts mainly and has not been tested for other types of charts (though I expect them to operate similarily).

This class follows the standards and formats listed at: http://docs.fusioncharts.com/charts/contents/ChartSS/MSLine.html
I did not create FusionCharts, you can view it at: http://www.fusioncharts.com/
AngularJS FusionCharts: http://fusioncharts.github.io/angular-fusioncharts/#/demos/ex1

How to Use

First require the file FusionChart.php:
require_once('FusionChart.php');
This will give the current PHP script access to the class

Create the FusionChart object:
$x = new FusionChart($args);
Follow the argument criteria to create the object correctly

Argument Criteria
The FusionChart class accepts an array as the argument for the constructor. The array should contain the following formatted information:

$args = array( 'chart_attributes' => array(), 'dataset' => array(), 'categories' => array() );

'chart_attributes' should be an associative array whose key holds the chart attribute name and value is the attribute value.

Example:
'chart_attributes' => array('caption' => 'First Chart!', 'xasixname' => 'Date');

'dataset' should be an associative array that holds the series name as the key and for the value, an array that holds all the data for that series. Currently, the class checks for uniqueness of series (if you set unique_series to true), but this is a bit redundant because array keys must be unique anyways. Will be removed in the future:

Example:
'dataset' => array('seriesa' => array( 1, 2, 3, 4, 5), 'seriesb' => (15, 23, 44, 45, 43));

'categories' should be an array of all the categories you want. The number of categories should normally be equal to the maximum number of values you want to be graphed (so if your dataset 'seriesb' has 5 values and 5 is the largest dataset, than categories should theoretically be 5)

Example: `'categories' => array('2014-05-03', '2014-05-04', '2014-05-05', '2014-05-06', 2014-05-07');`

Printing the Class into the FusionChart JSON string
To print the object into the formatted FusionChart JSON string, just use:
echo json_encode($obj, JSON_PRETTY_PRINT);
You may also have to set your header information to: (for some XMLHTTPRequests):
"Content-Type: application/json"

Extra Options

The class constructor also accepts two other (optional) options which are unique_series and unique_categories. This to make adding in data easier, especially if your `SELECT` query on `MySQL` does not have a unqiue column. If these values are set to true, than the class will not add repeat series or categories, and will simply ignore them.

About

A PHP Class for FusionChart that assigns attributes the PHP way and can be printed into the correct JSON string for use to be parse by a Javascript file or printing to the PHP page

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages