![]() |
|
stOfcPlugin - 1.0.2Integrates "Open Flash Chart" for symfony framework. |
|
stOfcPlugin class provides abstraction for Open Flash Chart.
Creates Flash Chart based on an array of data.
Using stOfcPlugin you can create different types of charts like,
Bar Chart
Line Chart
3D Bar Chart
Pie Chart
Bars + Lines
Area Chart
Scatter Chart
Mixed Scatter Chart
Candle
Install the plugin:
$ symfony plugin:install stOfcPlugin
Or download it and unzip in your /plugins directory
symfony 1.3/1.4: Enable the plugin by hand in ProjectConfiguration.class.php as it was not installed via the plugin:install task
// config/ProjectConfiguration.class.php class ProjectConfiguration extends sfProjectConfiguration { public function setup() { $this->enablePlugins('stOfcPlugin'); } }
Clear you cache:
$ symfony cc
You just need to add the following line of code in your template where you want to create graph
<?php stOfc::createChart(500, 250, '@bar_chart_data', false); ?>
The first three parameters are height, width and URL for data
Following is an example of a bar chart:
public function executeBarChartData() { $chartData = array(); //Array with sample random data for( $i = 0; $i < 7; $i++ ) { $chartData[] = rand(1,20); } //To create a bar chart we need to create a stBarOutline Object $bar = new stBarOutline( 80, '#78B9EC', '#3495FE' ); $bar->key( 'Number of downloads per day', 10 ); //Passing the random data to bar chart $bar->data = $chartData; //Creating a stGraph object $g = new stGraph(); $g->title( 'stOfcPlugin example', '{font-size: 20px;}' ); $g->bg_colour = '#E4F5FC'; $g->set_inner_background( '#E3F0FD', '#CBD7E6', 90 ); $g->x_axis_colour( '#8499A4', '#E4F5FC' ); $g->y_axis_colour( '#8499A4', '#E4F5FC' ); //Pass stBarOutline object i.e. $bar to graph $g->data_sets[] = $bar; //Setting labels for X-Axis $g->set_x_labels(array( 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday' )); // to set the format of labels on x-axis e.g. font, color, step $g->set_x_label_style( 10, '#18A6FF', 0, 2 ); // To tick the values on x-axis // 2 means tick every 2nd value $g->set_x_axis_steps( 2 ); //set maximum value for y-axis //we can fix the value as 20, 10 etc. //but its better to use max of data $g->set_y_max( max($chartData) ); $g->y_label_steps( 4 ); $g->set_y_legend( 'stOfcPlugin', 12, '#18A6FF' ); echo $g->render(); return sfView::NONE; }
Following is an example of a line chart:
public function executeLineChartData() { $chartData = array(); for( $i = 0; $i < 7; $i++ ) { $chartData[] = rand(0, 50); } //Create new stGraph object $g = new stGraph(); // Chart Title $g->title( 'stOfcPlugin example', '{font-size: 20px;}' ); $g->bg_colour = '#E4F5FC'; $g->set_inner_background( '#E3F0FD', '#CBD7E6', 90 ); $g->x_axis_colour( '#8499A4', '#E4F5FC' ); $g->y_axis_colour( '#8499A4', '#E4F5FC' ); //Use line_dot to set line dots diameter, text, color etc. $g->line_dot(2, 3, '#3495FE', 'Number of downloads per day', 10); //In case of line chart data should be passed to stGraph object //unsing set_data $g->set_data( $chartData ); //Setting labels for X-Axis $g->set_x_labels( array( 'Mon','Tue','Wed','Thu','Fri','Sat','Sun' ) ); //to set the format of labels on x-axis e.g. font, color, step $g->set_x_label_style( 10, '#18A6FF', 0, 1 ); //set maximum value for y-axis //we can fix the value as 20, 10 etc. //but its better to use max of data $g->set_y_max( max($chartData) ); $g->y_label_steps( 5 ); // display the data echo $g->render(); echo $g->render(); return sfView::NONE; }
Following is an example of pie chart,
public function executePieChartData() { $chatData = array(); for( $i = 0; $i < 7; $i++ ) { $data[] = rand(5,20); } //Creating a stGraph object $g = new stGraph(); //set background color $g->bg_colour = '#E4F5FC'; //Set the transparency, line colour to separate each slice etc. $g->pie(80,'#78B9EC','{font-size: 12px; color: #78B9EC;'); //array two arrray one containing data while other contaning labels $g->pie_values($data, array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')); //Set the colour for each slice. Here we are defining three colours //while we need 7 colours. So, the same colours will be //repeated for the all remaining slices in the same order $g->pie_slice_colours( array('#d01f3c','#356aa0','#c79810') ); //To display value as tool tip $g->set_tool_tip( '#val#%' ); $g->title( 'stOfcPlugin example', '{font-size:18px; color: #18A6FF}' ); echo $g->render(); return sfView::NONE; }
Following is an example of 3D bar chart,
public function execute3DBarChartData() { //Create new stBar3D object and set the transparency and colour. $redBar = new stBar3D( 75, '#d01f3c' ); $redBar->key( '2007', 10 ); //random data for( $i = 0; $i < 12; $i++ ) { $redBar->data[] = rand(200,500); } //2nd Bar $blueBar = new stBar3D( 75, '#356aa0' ); $blueBar->key( '2008', 10 ); //random data for 2nd bar for( $i = 0; $i < 12; $i++ ) { $blueBar->data[] = rand(200,500); } $g = new stGraph(); $g->bg_colour = '#E4F5FC'; $g->title( 'Number of downloads in 2008 and 2009', '{font-size:20px; color: #18A6FF;}' ); $g->data_sets[] = $redBar; $g->data_sets[] = $blueBar; //to create 3d x-axis $g->set_x_axis_3d( 10 ); $g->x_axis_colour( '#8499A4', '#E4F5FC' ); $g->y_axis_colour( '#8499A4', '#E4F5FC' ); $g->set_x_labels( array( 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct', 'Nov', 'Dec' ) ); $g->set_y_max( 500 ); $g->y_label_steps( 5 ); $g->set_y_legend( 'stOfcPlugin', 12, '#18A6FF' ); echo $g->render(); return sfView::NONE; }
See stOfcExample module for details.
setting.yml
all:
.settings:
enabled_modules: [stOfcExample]
Stay tuned for detailed documentation
cheers :)
This plugin is sponsored by SQL Technologies
