Last updated April 18, 2009. Created by kong on April 4, 2009.
Edited by Kessin. Log in to edit this page.
Open Flash Chart 2 API allows you to use a third party API a.k.a. "external library" to create the chart object.
These "external libraries" usually come in a package of files contained in a directory, and you will have to include a file from the package in your PHP code in order to use the library functions. For example, if you want to use the PHP library that comes with Open Flash Chart 2 package, you have to include the file php-ofc-library/open-flash-chart.php in your code.
Open Flash Chart 2 API helps simplify that process by automatically including the file you want. Here's how to add an external library to Open Flash Chart 2 API:
- Download and extract the library.
- Copy the library directory to Open Flash Chart 2 API module directory
- Go to Open Flash Chart 2 API settings page (
admin/settings/ofc_api) - Locate the fieldset named "External library". If you are not using an external library, it will be collapsed by default.
- Make sure the option "Use external library" is checked
- Enter the path to the library file you want to include (relative to the module's path)
- Save configuration and that's it :)
Now you can create a chart object using the external library functions. For example, if you use the php-ofc-library and want to create the chart in this tutorial page, you can just copy and paste the code like this:
<?php
$data = array();
for( $i=0; $i<6.2; $i+=0.2 )
{
$tmp = sin($i) * 1.9;
$data[] = $tmp;
}
// this line is not needed since Open Flash Chart 2 API will take care of the inclusion of the file
// include '../php-ofc-library/open-flash-chart.php';
$chart = new open_flash_chart();
$chart->set_title( new title( 'Area Chart' ) );
//
// Make our area chart:
//
$area = new area();
// set the circle line width:
$area->set_width( 2 );
$area->set_default_dot_style( new hollow_dot() );
$area->set_colour( '#838A96' );
$area->set_fill_colour( '#E01B49' );
$area->set_fill_alpha( 0.4 );
$area->set_values( $data );
// add the area object to the chart:
$chart->add_element( $area );
$y_axis = new y_axis();
$y_axis->set_range( -2, 2, 2 );
$y_axis->labels = null;
$y_axis->set_offset( false );
$x_axis = new x_axis();
$x_axis->labels = $data;
$x_axis->set_steps( 2 );
$x_labels = new x_axis_labels();
$x_labels->set_steps( 4 );
$x_labels->set_vertical();
// Add the X Axis Labels to the X Axis
$x_axis->set_labels( $x_labels );
$chart->add_y_axis( $y_axis );
$chart->x_axis = $x_axis;
// remove this so it won't output the JSON string
// echo $chart->toPrettyString();
?>Now $chart contains the data structure ready to be sent to open-flash-chart.swf, you may want to
<?php
return $chart;
?>if it is in a function, or you may want to
<?php
print ofc_api_render($chart);
?>if it is just a quick PHP snippet.
You may want to read on how to render the chart data.