Wednesday, 13 August 2008

Apex and FusionCharts (or There be dragons at the end of the earth)

According to an article I read on the BBC website there's a whole coterie of people out there who still believe that the earth is flat. Yes, they're a bunch of crazies but I'm kinda grateful they exist cos they've given me the opportunity to use the word coterie in a sentence: admit it, you never have, have you?

But when you ask these flat-earthers what is beyond the edge of the earth they've got one simple answer: More earth.

Oracle Application Express, I've found, is kinda like that. Yes, you're occasionally going to hit the outer edges of its capabilities, but if you push against these edges you find more earth. Today I had a requirement to integrate a genogram into my app. It was immediately obvious that I'd need a Flash chart. And then it became immediately obvious that none of the pre-packaged Flash charts (pies, lines, bars, dials etc) would fullfil the need.

All of which led me to FusionCharts, which is a brilliant set of flash charts and widgets. All I had to do was figure out how to integrate it into my app. First I had to write a function to extract the data I needed from my database and output it as correctly-formatted XML. That bit was easy so I won't bore you with it.

Next I uploaded the Flash (SWF) file for my chart into my workspace. (Tell me something: when you upload an image to your application using Apex's image uploader you refer to it by pointing at # APP_IMAGES#, so how do you think you'd refer to a file you've uploaded using Apex's file uploader? #APP_FILES#? Wrong! Illogically, all files uploaded into your application should be pointed at using the #APP_IMAGES# substitution string.)

Finally, I created a dynamic PL/SQL content region outputting the necessary wrapper tags for my Flash movie (which I copied from the FusionCharts examples), pointing it to my uploaded swf file and feeding it the XML from my database function (which I call in "before regions" page process).

And there you have it - more earth. Suddenly you are no longer constrained by the limited list of flash charts that come packaged with Apex. Easy-peasy when you know how.

(Apparently, Scott Spendolini recently presented a paper on integrating FusionCharts into Apex but I couldn't find it on the internet. Go ye forth and Google for it for thou might have more luck than I.)

9 comments:

Alp said...

Sorry, I've forgot to get the link on AnyChart website: http://anychart.com/

Scott said...

David,

You can find a copy of my presentation here: http://maop.org/BBL/March_Spendolini.pdf

Thanks,

- Scott -

David Njoku said...

Thanks for the link, Scott. I searched everywhere for it yesterday! However I'm kinda glad I didn't find it; it forced me to think it through and figure it out for myself.

I had a look at AnyChart, Alp, but none of their charts met this particular requirement. Am I right in thinking that all flash charts in Apex are AnyChart-based? I'm sure I read that somewhere. Thanks for the link though.

Alp said...

Yes. Usual apex charts are based on AnyChart v.3, but interactive reports use AnyChart v.4. And it's possible to use all the power of AnyChart just by passing proper XML to AnyChart.swf

Anonymous said...

David / Scott

Do you have a demo I can view.. I really want to get Fusion Charts working ... Apex AnyCharts are not good enough for me..
Or a detailed example on how to create a Fusion Chart..
I downloaded Scotts march PDF.. but not infor for me to fill in gaps..

Tx
dean

Anonymous said...

Seen these : http://teethgrinder.co.uk/open-flash-chart/ ?

free, open source :-) all good :-)

David Njoku said...

Hi Dean,

I don't have an online demo, unfortunately, but I'm confident you should be able to get it to work easily enough.

The FusionCharts website explains how to create the charts; all you need to suss is how to integrate them into your application. What I did was load the SWF file (that I got from FusionCharts) to my application, and then call it while passing the XML to it.

If you let me know what exact bit you're having trouble with I'll be happy to see if I can assist.

David.

Anonymous said...

Hi David,

Like Dean, I'm very interested in getting FusionCharts working. I've got most of the way with this but it's the final step - pushing the data into the chart - which I'm having problems with. Could you elaborate on 'feeding it the XML from my database function'?

I've had Ajax working with Apex previously - is this similar (in theory)...?

Thanks,
David

Anonymous said...

Please take a look at AnyChart for APEX new version:
http://www.anychart.com/products/anychart/docs/upgrade-charts-in-apex.php