RCAmChartsBundle
RCAmChartsBundle
eases the use of AmCharts to display rich graph and charts in your Symfony2 application by
providing Twig extensions and PHP objects to do the heavy lifting. The bundle incorporates the JS charting
library AmCharts., (*1)
DRY out your chart code by writing it all in PHP!, (*2)
Content
License
RCAmChartsBundle is released under the MIT License. See the bundled LICENSE
file for details., (*3)
Please note that the AmCharts JS library bundled with the project is free for commercial use provided you retain the advertisement., (*4)
How to get started
Installation
-
Add the following to your composer.json
file, (*5)
"require": {
...
"rcousens/amcharts-bundle": "dev-master@dev"
...
}
-
Run php composer.phar update "rcousens/amcharts-bundle"
, (*6)
-
Register the bundle in your app/AppKernel.php
:, (*7)
php
<?php
...
public function registerBundles()
{
$bundles = array(
...
new RC\AmChartsBundle\RCAmChartsBundle(),
...
);
...
, (*8)
-
Install the static assets, (*9)
php app/console assets:install --symlink web
Usage
Basic Pie Chart
In your controller ..., (*10)
``` php
<?php
use RC\AmChartsBundle\AmCharts\AmPieChart;, (*11)
// ...
public function chartAction()
{
// Chart
$pieChart = new \RC\AmChartsBundle\AmCharts\AmPieChart();
$pieChart->renderTo('piechart');
$pieChart->setTitleField('number');
$pieChart->setValueField('column-1');
$pieChart->addData(array('number' => '1', 'column-1' => 10));
$pieChart->addData(array('number' => '2', 'column-1' => 40));
$pieChart->addData(array('number' => '3', 'column-1' => 30));
return $this->render('::template.html.twig', array(
'chart' => $chart
));
}
In your template ...
``` html
VoilĂ !, (*12)