dbFusionChartPlugin : Simple Example

This first example will show you howto integrate a FusionChart (free / non-free ) graph in your symfony application, using the dbFusionChartPlugin . I will explain 'example1' included in version 0.0.2 of our plugin.

The Result

Before getting to the code, here is what the final graph/chart will look like
[partial]dbFusionChartExample/example1[/partial]
 

The Partial

The example1 is a partial that looks like this
[code]dbfusionchart-example1-partial[/code]
As you can see the code in this partial is pretty easy. First you tell the symfony application to load the FusionChart helper (using : use_helper). After that you load the graph/chart itself. dbfusionchart_js takes multiple arguments, the most important are the first 2.
  • the first argument is the type of chart (using class constants)
  • second argument is the url to the xml
  • extra arguments tell the dbFusionChart how big the chart should be (width & size).
Very important in the url to the xml is that symfony knows it needs to return valid xml (an no html).

The Action

In the action.class of the dbFusionChartExample module we have the following action :
[code]dbfusionchart-example1-action[/code]

Line 5 – 6
tell symfony to not include the debug bar and send the response as XML (and not html)
On line 8 you will see the declaration of the chart. The classes are pretty smart, but the above example is a very basic example (copy pasted from FusionChart documentation).
When you are ready setting the properties of your chart (we will explain that in further posts), you tell symfony to return the xml (see line : 40).
 

No comments:

Post a Comment