Using FusionCharts with RoR > Plotting data from a database |
In this section, we'll show you how to use FusionCharts and Ruby to plot charts from data contained in a database. We'll create a pie chart to show "Production by Factory" using dataXML method. For the sake of ease, we'll use an MySQL Database. You can, however, use any database with FusionCharts including MS SQL, Oracle, Access etc. Database configuration will be available here Download Package >> RoR >> config >> database.yml. In the production version, we have used database named as fusioncharts. Before you go further with this page, we recommend you to please see the previous section "Basic Examples" as we start off from concepts explained in that page. |
| All code discussed here is present in Controller : Download Package > Code > RoR > app > controllers > dbexample_controller.rb. Rhtml : Download Package > Code > RoR > app > views > dbexample folder. |
| Database Structure |
| Llet's quickly have a look at the database structure. |
![]() |
The database contains just 2 tables:
For demonstration, we've fed some dummy data in the database. Let's now shift our attention to the RoR that will interact with the database, fetch data and then render a chart. |
| Building the Ruby for dataXML Method |
|
The following actions are taking place in this code:
When you now run the code, you'll get an output as under: |
![]() |