Murray Picton

Render Fusion Charts on the server with .NET

If you are a regular reader of my blog, you will remember my “How to render Fusioncharts completely on the server” post which explained for to render Fusion Charts on the server using PHP. Since then, I have been in discussion with the great support team at Fusion Charts and they have written a .NET assembly that will allow rendering a lot easier than using the PHP that I wrote about previously.

If you don’t know what Fusion Charts is, it is a flash based charting program that creates great looking charts and is really easy to use. You can find it at http://www.fusioncharts.com/.

First up, if you haven’t already, you will need a Windows machine to be able to get .NET working. The best way to do this for LAMP developers is to create a virtual machine, to find out how to do that take a look here and then you will be able to install Windows on a Linux machine.

Using the FusionChartsImageSaver.dll

If you haven’t already, get in touch with the support team at Fusion Charts and ask for the .NET renderer. They will send through a set of .dll files and some sample code to get you started. To get it working on your server, you just need to put the .dll files somewhere that you can reference and then take a look at the sample code. You will need to make sure you have the latest version of Flash installed on the system as it is used to render the chart. This is an easy step to forget, so make sure you have Flash!

The sample code

The sample code that is sent through is written in C#. I must confess, I do not use C# regularly in my day to day programming but, as with a lot of programming languages, spending a little time on it will make it easier to use and it will be quick to understand. The nuts and bolts of the sample code is the following line:

string fileName = "FusionCharts/fc.png";
ServerSideImageHandler ssh = new ServerSideImageHandler(Server.MapPath("FusionCharts/Column2D.swf"), 500, 400, xml,"", Server.MapPath(fileName));
ssh.BeginCapture();

Hopefully, this is not too complicated. What it is doing is naming an output file location, setting up a new instance of the ServerSideImageHandler class with the appropriate parameters and then running the ssh.BeginCapture(); function that will render the chart and output it to your selected file. You must remember that the output location must be writeable – this is another easy thing to forget.

So, that is the basics of the ServerSideImageHandler. It’s quite easy really when it comes down to it.

Oddities

There are a few oddities that I have come to notice with the assembly that the guys at Fusion Charts have created.

  1. The BeginCapture function is synchronous. This means that calling the function and then checking for the file straight afterwards doesn’t always work. It all comes down to the fact that the C# program will continue running after the BeginCapture function and doesn’t pause until it is complete. There is an easy way to create this functionality by creating a loop that checks if the output file has been created and only continuing once it has.
  2. There are some XML chart attributes that are available in the standard Fusion Charts flash library that don’t work in this. The main one I have found so far is the “bgswf” attribute.
  3. There is no option to turn on any debugging. This means if there is a problem rendering the chart, there is no opportunity to find out why and fix the issue.
  4. It seems that some charts are not supported. I haven’t been able to render the thermometer widget through this facility. Most of the charts work fine but it seems there is at least 1 that doesn’t work.

The ServerSideImageHandler is a great tool from the Fusion Charts team. I think there is still some work to be done on it, and I think it may still be in beta so they shouldn’t be complained about too heavily yet. This tool now allows programmers a lot more functionality with their Fusion Charts and, in my case I have found a massive speed improvement between rendering the charts in the standard way and using this .dll.

If you have liked this post, please use the links in the top right of the screen to share it with others and take a look round the rest of my site for other great posts. Thanks for reading!