Saturday, March 22, 2008

FusionCharts. Cool flash charts with a free distribution



[kml_flashembed movie="http://www.boundingbox.es/wp-content/uploads/2008/03/fcf_mscolumn2dlinedy.swf" height="300" width="600" fvars=" dataURL= http://www.boundingbox.es/wp-content/uploads/2008/03/temperature_080321.xml ; chartWidth = 600 ; chartHeight = 300"/]
fcf_mscolumn2dlinedy.swf
temperature_080321.xml

I have to admit that I wasn´t very proud of my matplotlib code to represent the temperature values I was gathering with Arduino. It was pretty complex, and too slow. Meanwhile I´ve been facing several issues that requires data representation and searching for alternatives I came across a nice solution, flash charts. I found two projects, one open source, Open Flash Charts, and another commercial, but with a free distribution, FusionCharts


Comparing

At first I was attracted by OpenFlashChart because it has a python binding and it was open source, soon I realized that this library was to focused on PHP and web developments. The python code was mod_python oriented, and I wanted to create flash charts without requiring a web server. Although I finally could create several charts, there was no way to redirect the default loading folder of the .swf and I couldn´t reproduce several examples such as bar links. May be I wasn´t to inspired to solve those problems but I decided to test the other option.

On the other hand, I downloaded FusionCharts. After following the first examples, I realized that this is a more mature solution. Documentation is great, and all the examples worked properly as expected. I also was happy when a show that all chart requirements I had were provided in the free distribution. The only thing I missed was a python mod to create charts easily, so I started working on it.

The code

This is just a simple python module with several classes to encapsulate the concepts underneath FusionCharts:
  • DataSetValue: Class responsible for storing a data set value and to be able to render in to XML code as FusionCharts expect it
  • DataSet: Class responsible for storing dataset attributes and to be able to render in to XML code as FusionCharts expect it
  • MultipleDataSet: Class responsible for storing a multiple series data set and to be able to render in to XML code as FusionCharts expect it
  • Chart: Base class for all the charts responsible to implement all the common attributes and methods of all type of charts
  • SeriesChart: Class responsible for storing Single Series, Multiple Series and Combination Charts attributes and to be able to render in to XML code as FusionCharts expect it
Currently, it only support all charts that belongs to the Single Series, Multiple Series and Combination. Just as an example here you can see python code to generate a column2D representation


    # Single Dataset
    hours = ['9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00']
    temperatures = [10.0,17.0,18.0,19.0,22.0,21.0,20.0]
    temperatureDataSet = DataSet("Temperatures", None, ´ff0000´, hours, temperatures)

    singleChart = SeriesChart(
            'singleSeriesChartTest',
            'Column2D',
            700, 300,
            temperatureDataSet,
            "Temperatures",
            "Hours",
            "C")
    singleChart.SetAttribute('subCaption', '(20/03/2008)')
    singleChart.SetAttribute('yAxisMinValue', 5.0)
    singleChart.CreateCharHTML()

1 comment:

  1. Hi there,

    In ur XMLRender functions if you modify the line where u compare the type to StringType to be:


    if type(attrValue) in [StringType, UnicodeType]


    it will work for unicode too..eg. when the x/y axis names r in international characters, unicode etc...

    just thot i'd let u know...

    thx...
    Jimmy

    ReplyDelete