Open Flash Charts + Embedded JSON Data
I've been using Open Flash Charts to display data on the upcoming SimpleStats, and still think that they absolutely rock. However, I did have one worry about the flash chart getting the JSON data from a URL - it seemed a bit unnecessary given the dynamic-ness of the account pages, and would allow users with public accounts to gain access to the data to use with their own stuff. This would cause extra server load, and I wouldn't be able to cache the data as ruthlessly as I would for the SimpleStats API.
So, I turned over to the Open Flash Charts site to see about embedding data right into the page that the chart was being rendered on. I found it was indeed possible - but with the inclusion of json2.js. I didn't really want to add any more JavaScript includes to the site, so set about looking at why you need it - and it turns out you don't.
Instead of using $chart->toPrettyString(); in the chart PHP file, you can simply use the built in PHP5 json_encode($chart);. JavaScript can then go on to parse the string given by PHP's JSON without any extra processing - thanks to the way PHP encodes JSON without whitespace.
Or, if you're a PHP 4 user, use the $chart->toString(); method built into the Open Flash Charts 2 class. Thanks to vtstarin in the comments.
So, then all you do is add a JavaScript function to your page like the one below, and the chart swf file somewhere in the page.
function open_flash_chart_data(){
return '{"elements":[{"type":"bar","values":[9,8,7,6,5,4,3,2,1]}]}';
}
The flash chart calls open_flash_chart_data() when the page loads if there isn't anything set in its URL.