The Weekly World Whatever. Served Fresh Daily. A weblog featuring a mixture of programming tidbits, business news & opinion, book reviews and maybe even some fun & games (if you’re lucky).

Web developers: 4 chart widgets you can use for free

Posted by Robert S.

I have been looking for some free and fancy charts to spice up web application I’m building for a client. The four most useful tools I came across were: Open Flash Charts, Google Chart API, Yahoo! UI Library Charts, and Sparklines.

Open Flash Charts

Open Flash Charts by John Glazebrook takes the top spot with the most powerful chart widget. It’s Flash-based, and rather easy to use. All you need is a couple of lines of PHP (or Java, Perl, Python, Ruby on Rails, or .NET) to embed the chart, and a script on your server to output some data.

<?php
include_once 'ofc-library/open_flash_chart_object.php';
open_flash_chart_object( 500, 250, 'http://'. $_SERVER['SERVER_NAME'] .'/chart-data.php', false );
?>

Check out the Open Flash Charts tutorial for more details. It takes about 15 minutes to work through the first tutorial and the results are great.


Open Flash Charts sample

Google Chart API

The Google Chart API is fun, easy, and doesn’t rely on Flash at all. Which of course means it lacks the interactivity of a Flash-based chart, but it’s compatible with more platforms and is by far the easiest to implement. One drawback is that (at the time of writing) it does not support negative numbers without cheating.

The Google Chart API is controlled entirely through the <img> HTML tag. An image with a URL of http://chart.apis.google.com/chart?chs=200×125&chd=s:helloWorld&cht=lc&chxt=x,y&chxl=0:|Mar|Apr|May|June|July|1:||50+Kb produces the following:


Google Chart API sample

Full documentation is available on the Google Chart API website.

Yahoo! UI Library Charts

Yahoo!’s offering, Yahoo! UI Library Charts, is still marked as “experimental”, but it looks as though it will turn out to be very powerful. If you’re familiar with other components of the Yahoo! UI Library, getting started should be a breeze. Like Open Flash Charts, it uses Flash for display.

The biggest downside appears to be a lack of any way of easily embedding a graph in a blog post such as this one. To see Yahoo!’s charts in action, click here.

Sparklines

Sparklines are, as defined by Edward Tufte, small, high resolution graphics embedded in a context of words, numbers, or images (from Wikipedia).

If that sounds like what you’re looking for, the Sparkline PHP Graphing Library is for you. With just a few lines of code, you can represent data on your website with image-based sparklines, like Sparkline example and Sparkline example.

As you will see in the documentation, generating a sparkline is dead easy:

<?php
require_once('/sparkline/Sparkline_Line.php');
$sparkline = new Sparkline_Line();
$sparkline->SetData(0, 15);
$sparkline->SetData(1, 18);
$sparkline->SetData(2, 9);
$sparkline->Render(100, 20);
$sparkline->Output();
?>

In Conclusion

All of the above are fantastic tools which can greatly simplify the task of embedding charts in your web applications. Depending on your needs, one of them will almost certainly be a fit for your project. I know I’ll be making use of all four in upcoming projects.

If you have a tip on another chart widget, please share below.

Is the Zend Framework’s Zend_Cache slowing you down?

Posted by Robert S.

I recently discovered that one of our websites had become so painfully slow that it was taking several seconds to display a cached file. We are using Zend_Cache, from the Zend Framework, to cache frequently accessed content. On the Zend_Cache backend we are using Zend_Cache_Backend_File to cache thousands of documents. We were storing the cache files in a directory that, in addition to the Zend cache files, had thousands of other temporary files unrelated to Zend_Cache.

It was a poor decision on my part to pile all these files into one directory, and one that went unnoticed until the number of files on the site started to grow. If you happen to find yourself in the same situation, here’s what you can do:

Put the cache files in their own directory, and use a hashed directory structure. Zend_Cache_Backend_File supports this through the hashed_directory_level setting. See the documentation for more information.

Sample code:

<?php
require_once ("Zend/Cache.php");

$fOpt = array (
'lifetime' => 3600,
'automatic_serialization' => true
);

$bOpt = array (
'hashed_directory_level' => 2,
'cache_dir' => '/tmp/'
);

$cache = Zend_Cache :: factory('Core', 'File', $fOpt, $bOpt);
?>

Piwik: Open-source web analytics

Posted by Robert S.

Piwik is an open-source web analytics project worth keeping an eye on. I suspect as it evolves it will become a great alternative to Urchin, the self-hosted edition of Google Analytics.

The problem that many have with Google Analytics is that you lose control of your data to a third party. Most existing alternatives to Urchin are either expensive or not nearly as feature-rich as Google’s offering. Piwik aims to change this by providing a free alternative that can be extended through the use of plug-ins created by the Piwik community.

The graphs that are part of Piwik can be embedded in your website or on your company intranet, which provides companies with a great deal of control over the display of their web analytics data.

Embedded Piwik graph

I look forward to seeing future releases of this product.

Living-in pupil’s exam success, needed for high-fliers? (8, 4)

Posted by Robert S.

Good luck folks

Thief pilfers hot new fashion (10)

Posted by Robert S.

I promised fun and games, so you’re getting fun and games.

Every day (well, some days) I’m going to pick a clue from my morning crossword and give a prize (a congratulatory note in the comments) to the first person to solve it. Some will be clues I’ve cracked and others will be clues I’m stuck on. I’ll try to pick clues I think are exceptionally clever and clues that make for an interesting blog post title.

Today’s clue I have not yet solved, but I do know the answer is 10 letters and the first letter is s.

You’ll need to read up on cryptic crosswords to play along.