act:ualise | technology

15 Jan, 2009

Open Flash Chart 101: Make it %#$@!?* work

Posted by: j pimmel In: information visualisation|javascript

I have recently been attempting to get my head around Open Flash Chart to, at the very least, get an equivalent ‘Hello World’ version running before I run off customising it. Should be simple right? Well yes, once you get around a real showstopping gotcha which isn’t documented out there.

The starting point, this tutorial example. As you can see, everything is well with that example. Following my usual logic, I downloaded the following relevant page items

  • json2.js
  • swfobject.js
  • open-flash-chart.swf

I created a local HTML into which I copy pasted the pertintent source from the tutorial example, changing script and page references to use same directory for the three page items above. I fully qualified the JSON data url to {“data-file” :  ”http://teethgrinder.co.uk/open-flash-chart-2/gallery/tooltip.php” } - cross site yes, but its just JSON data right?

On loading the chart into my browser offf the filesystem I didn’t get the chart expected, instead I got what is pictured below

Open Flash Chart loaded from Local HTML

Using Firebug reveals some interesting things – yes the JS files are there and loading. Given that the spinning thing is in fact the SWF file loaded into the browser that has to have loaded too and it’s running too.. well, sort of. So why no graph?

Make my data local?

Fair enough I thought, perhaps its some cross-site thing after all. I made the JSON data that is handed to the SWF local to the page; embedding JSON data in page for the graph is shown by example here and making that change was easy. But once again no joy.

Make my data served?

I couldn’t see why, but maybe serving the content over HTTP would do something for me. Taking all the same resources and uploading them to the server here was what finally delivered a working chart example of my own making, reading the JSON data from inside it’s own page.

But why?

Assuming you have visited the above links, you will have noted the alerts which come up when the browser SWF successfully drawing a graph. I reasoned that maybe a local page load wasn’t firing the Javascript onLoad event? A quick local page test of

<body onLoad="alert('hello world!')">

proved me wrong.

Just don’t cross-site the content

What is clear is that no working charts I have found make references to any SWF/JS/JSON data resources which are outside of the same domain. Thats perhaps logical, but you might also like to be notified as such – at present OFC gives you no indication, not even a hint, that you have this problem. The only instance where you get a sniff of this is revealed in Firebug when visiting this version of the chart I am serving.

Coming up short

Sadly I dont have the answer to why the chart fails to draw when you attempt to run it locally from files vs when it is served up.

I know that the SWF is executing some ActionScript which is doing the magic somewhere which ultimately leads to the invocation of the Javascript ‘ofc_ready’ method. Its not clear how those bindings are different when loaded locally vs when served, but this problem could also easily be masked by cross-site complexities. Its seems pretty evident that the browser is triggering an event in the loaded SWF plugin in one instance but not the other.

If anyone has any deeper knowledge or thoughts as to why it would be good to know the details – please feel free to comment!

UPDATE (30th March 2009): We recently found out how to toggle local loading. The reason it doesn’t comes down to flash player sandboxing

Add permission for SWF files (woot!)

6 Responses to "Open Flash Chart 101: Make it %#$@!?* work"

1 | monk.e.boyNo Gravatar

January 20th, 2009 at 5:37 am

Avatar

This is one of the more stupid blog posts about the charts I have read.

So, you *didn’t* follow the tutorial and it didn’t work, and somehow this is the charts fault.

Then you realise your mistake and continue to *not* follow the tutorial and still can’t get the charts to work.

Then you finally get the charts working and wonder if cross domain queries may be the problem. Yes it is. But you decide *not* look up how to set the security settings in the swfobject to allow cross domain call? ;-)

Why not drop into the forums and ask around. Allowing cross domain calls is a security risk (imagine charting financial info that a 3rd party hacker could change at will)…

I wonder if you’ll allow this comment or not?! I doubt it.

monk.e.boy

2 | j pimmelNo Gravatar

January 20th, 2009 at 6:11 am

Avatar

Well monkeyboy, I have to treat your comments with a sarcastic smile and thanks, but perhaps you can answer some questions that still remain.

Did i follow your tutorials? In fact I spent many hours poring over them again and again, viewing sources. Back on Dec 2nd I posted on your forums, though it was a while before I realised that wasn’t your main forum. A thought: maybe someone could just delete the old one? I don’t know – by that point In early December I had given up on OFC and was busy with other things.

Where on your site does it say explicitly that none of the tutorials will never work locally, no matter what you do? Where on your site does it explicitly say ‘you gotta serve this over http’ – or is it that I am supposed to infer from the fact you use PHP examples that it’s got to be served? Inference is pretty weak form of documentation if so.

So recently when I tried one last time to give it a go, the only word I hear from the Open Flash Chart community is flame and vitriol here. And apparently I’m to blame :)

Myself and my colleague, with 20 years of development experience behind us, had spent many hours trying to get to the bottom of why a stoopid local example didn’t work. So while we’re not cross-site scripting geniuses we’re aware of the issues, particularly of security. We’re not so aware why javascript that otherwise ordinarily runs locally doesn’t for ActionScript, but hey…

Someone could also have pointed out where the documentation exists online with some clear usage stipulations, because if they exist we never found them.

And lastly, as I mentioned in post, whatever happened to writing code where if the usage isn’t quite correct, the code might offer up a hint to help you correct your mistake? Is that a lot to ask?

My post is there to solely save others time where we wasted ours. We’re the first to admit to making mistakes or missing something, but you being a superhuman developer only have time to engage us negatively. So monkeyboy – oh enlightened one, my hero developer of OFC – would you care to answer any of the above?

3 | j pimmelNo Gravatar

January 21st, 2009 at 7:59 am

Avatar

To follow up, since posting back onto the forum several others have put forward some useful responses as to why the files were not working locally (which it doesn’t appear has been discussed before)

http://forums.openflashchart.com/viewtopic.php?f=3&t=522

4 | cirlceNo Gravatar

January 30th, 2009 at 1:56 am

Avatar

Hi guys,

I do think that OFC is a great and I am no offense to anyone.

But I have to mention that this j pimmel did do a great job too by having such an useful analysis. Yes he may not followed the official tutorial but there are always other situations. In fact I am developing a software that generates reports as local HTML file without any web servers. I wish to present some nice and interactive charts to the users and OFC is my first choice. I soon come into the same issue as j pimmel and this is the first help I can found from Google. Glad to know that I am not alone, and it’s really great to see some pointers for help here. Hopes it help solving my problem.

Thanks j pimmel again for this articule and also monk.e.boy for this great useful tool.

Have a nice day!

circle

5 | find duplicatesNo Gravatar

March 18th, 2010 at 5:05 am

Avatar

I agree with j pimmel.
OFC2 is great but the documentation is very poor for local use. The web site is quite messy too so at one point I ended with using OFC2 with OFC1 data files etc.

Anyway I finally got OFC1 running LOCALLY. Unfortunately it is far from the OFC2 features which I needed and decided to go for OFC2 …. now the security issues raised. It can not be run locally neither with a data file nor with a java script event.

The question is WHY? Why OFC1 works and OFC2 has security issues?

I really do not want to ask admin rights in my app in order to add the app folder in the trusted sandbox.
Can someone fix this?

Cheers.
Al

6 | ShanNo Gravatar

April 5th, 2010 at 8:32 pm

Avatar

Great, I wasn’t aware of the flash settings. Thanks for the explanation…

Comment Form

About

act:ualise | technical blog

notes, observations and obssessions on software quality, agile software development, testing and grails


part of the EnergizedWork experiment