views:

516

answers:

5

Hi all,

I need to understand a good way to design a web page with dynamically updated graphs. It should be something close to what stock market graphs look like (e.g. Google Finance), although with a bit more complicated functionality, which is not the point. Naturally I am thinking of writing an ajaxy-style flash control, which would communicate with the server through, okay, something like XMLHttpRequest, but from within flash code, and draw things basing on data received. Is this doable with flash? Does security model allow such kind of client-server interaction? If yes, could you think of any references for me to get started (similar opensource projects, articles, whatever)? Or should I forget about flash and use a Java applet right away?

An important thing to note: I don't think I can use Google charting API, because I need also to have user interaction. In the link above to Google Finance the user can drag the graph to and forth with the mouse, that's close to what I need (I will also need to implement some actions from the dropdown menu).

Thanks for your answers and opinions!

+2  A: 

I have used the Google Charts API to do this sort of thing. For a simple example, see my Sunrise and Sunset page. This page calculates sunrise and sunset times for a given latitude and longitude, all in Javascript, then uses the Google Chart API to replace the graph on the page with the requested data.

Update: The Stack Overflow reputation graph (see your user page) isn't Flash and yet allows interactive dragging. (Click and drag on the left to update the posts on the right that reflect the highlighted reputation region.) Perhaps you could look at how that is implemented.

Greg Hewgill
Sorry, I think I was a bit unclear. In my example (Google Finance) user can drag the graph with the mouse, and also there are things (labels, marks) written on the graph itself - all these things are important for me. So I can't use an out-of the box charting solution like Google Charting API.
azerole
A: 

I'm not sure about the Flash side of things, but this would be pretty simple to do in Silverlight. I am pretty sure you'd easily be able to make a server request in Flash too.

I'd do some searching for long polling.

Jacksonh
Thanks for your answer. In fact Silverlight is an interesting idea, but unfortunately it's Windows-only, which is not acceptable in my case.
azerole
There is always moonlight. see http://mono-project.com/Moonlight
Darren
+4  A: 

Try this: JQuery Flot

Flot is a JQuery plugin to plot graphs. You keep replotting in-place with the latest data at the desired frequency to generate a dynamically updated graph. It is based on the <canvas> tag. We use it successfully to generate pretty complex dynamically updated graphs in our applications. The updates are fetched via periodic AJAX calls.

Another alternative is YUI Charts

We did not explore this a lot but this uses Flash and AJAX like you wanted to do.

/RS

YUI Charts is a very interesting variant, I'm going to look more deeply into it. Thanks a lot!
azerole
+1  A: 

You have described Flex...

Simon
An interesting variant, I'll look into it, thank you! I wonder though if I get enough functionality just from Flex, without other things they offer for money (ILOG Elixir...)
azerole
Flex comes with some charting components (although you may need the pay-for version). If you want to build your own I think that using actionscript directly would be easier unless you wanted flex for other UI stuff.
John Burton
+1  A: 

This is very possible in flash. You can use the URLLoader class to obtain data from a server at run time and the draw your graph using a custom control. In actionscript3 you'd subclass the Shape class and write a little drawing code to draw your graphs. Flash has support for drawing and filling so it would probably be very good at this.

The flash client can poll the server for updates. Or if you want a "live" connection you can establish a socket connection to the server and let the server push updated data live. Flash is good for this as you can push XML data over the socket and use the built in support for processing the XML, or you can send binary data just as easily.

As for the security model it's just the standard flash one. You can make network connections back to the server that the swf file came from with no issues. If you want to make a connection to a different server then that server needs to give your client permission to connect to it by hosting a crossdomain.xml file

John Burton