RGraph is quick, attractive, easy to use and free for commercial use. Built on the widely supported canvas element desktop and mobile support is excellent and that allows you to create charts and dashboards that you can use on a wide range of devices. Owing to the fast rendering of the canvas tag, your charts can be up to 10x faster than Flash or SVG based libraries. This means you can create good looking and informative charts and dashboards.
php_RGraph Howto Guide
How to use php-RGraph
This guide is should help to understand the structure of php-RGraph and give you some advice howto use php-RGraph on your website.This Guide has four sections
- structure of php-RGraph charts
- Using templates
- Using php-RGraph on your website
- Using php-RGraph with Joomla!
structure of php-RGraph charts
Installation of php-RGraphInstallation is straight forward. Once you have downloaded installation file "php-RGraph-V2.zip", unzip it and upload all folders and files to your website into an accessible directory (or if you are using XAMPP, copy the folders and files into accessible directory). "Accessible" means that you may access all files via webserver (e.g. Apache) and browser. Please keep directory structure and naming of php-RGraph (do not rename any folders).
Then check if you can access php-RGraph's documentation using url: http://your-host/your-install-directory/RGraph/index.html. If this is OK, you may read RGraph's reference and try out the provided samples.
Structure of php-RGraph chart scriptsTo give you an idea how all works, you should check some of the provided samples. (please use url http://your-host/your-install-directory/RGraph/doc/samples.html"). The samples page gives you the option to display a sample and see the php-code for creating the sample. This code illustrates the structur of php-RGraph. A php chart script always has this components:
- Define environment
- Define chart layout
- Define chart's data
- Define RGraph chart properties
- Build json object for RGraph
- Use template for rendering the chart (html creation)
Define environmentEvery chart script must know, where resources for charts are located. This is done with embedding (including) script "environment.php". If this script does not work correctly charts cannot be created. See the layout of "environment.php", which shows what information is needed:
Define chart layoutWith four lines of code you define major layout of you chart:
$template = "default.php"; $draw_option = "draw();"; $width = "500"; $height = "350";
Define chart's dataYou may define chart's data coming from various sources:
- define an array of numerical data direcly within your chart script
- retrieve data from file
- retrieve data from local or remote server
- retrieve data from MySql database
- retrieve data from csv file
- retrieve data from Google sheets
- generate data via math formula
Define RGraph chart propertiesFirst step is to define a rgraph_chart object:
$chart = new rgraph_chart($id, $data, $chart_type);
- "$id" is required and will define the canvas id (e.g. "cvs").
- "$data" defines the data to be used for charts
- "$chart_type" sets the desired chart type (e.g. "Pie")
valid types are:
$options = new rgraph_options($ini-file); $options->set_option("title", "My first chart); ...
php-RGraph "knows" about 450 different chart properties for almost all charts RGraph has offered. php-class rgraph_options has various methods to support you in providing chart properties, for more information see the reference guide, have a look at the samples or or visit the home of RGraph.
Build json object for RGraphOnce you have created the chart object and its properties you first define the properties ($options object) to the chart object and then create a json object to be used with RGraph:
$chart->set_options($options); $rgraph_json = $chart->toPrettyString();
Use template for rendering the chartThis is an easy task as the template's directory has been defined with "environment.php" and the template name has been defined already. So your code looks like:
include_once ($templates . $template);
Download php-RGraph Package
php-RGraph is free software - however you have to adhere to the GPL-license conditions to use it. Please learn more about GPL and free software at GNU Org.
To download php-RGraph please click the download button:
Version 2.1.0 (Build Level 22.214.171.124 - September 13th 2020)