Fri, 07 Dec 2007

CMS Series: Web charting and graphing libraries

We said we would roll out articles about our (Rails) Content Management System project and this is one of the very first, exposing our difficulties and decisions about deploying an usable, yet fancy charting functionality.
We won't spoil the surprise about the name of the project, yet. :)

The Quest

Finding a free, open source and (if possible) BSD or LGPL licensed library implementing chart and graphing functionality. We want to avoid licensing hell as much as we want to avoid bloated interfaces that obscure the statistical data more than abstracting it properly.

Requirements

  1. Capable of displaying technically complex data sets.
  2. Good performance: it must escalate well! (as much as we designed our product to do so).
    1. Efficient cache and server-side solution or browser supported implementation (ie. SVG based).
  3. Non-bloated, elegant code: we want to modify it and understand what's going on.
  4. Usable, simplistic interface (API): we hate working with an over complicated API.
  5. Nice, fancy, yet-not overly design-ish graphs:
    1. Experience shows that complicated graphs do nothing to improve the visibility of statistical data: better divide by many, than squeeze many in a few.
    2. Simple graphs and clean shapes are far more smooth and pleasing to the eye (Isn't the whole rounded corner spice about this anyway?).
    3. The more complex the data-set, the more simple a graph should be. The density of data displayed will be high and adding unnecessary fuss will just get in way of interpreting it properly.
  6. Non-hosted solution: we can't afford the risk of exposing customer or sensitive information to external hosts and services. We could do exceptions for publicly obtained data, but definitely not the internal information.

The Candidates

We haven't considered other commercial and open-source alternatives, simply because we didn't believe they fit our requirements upfront. But we might be wrong. Two of them are FusionCharts (commercial and Flash-based) and Open Flash Chart (Flash too, but open source). The latter seems nice but we don't have that much time to dive into its details. For PHP we have JpGraph, which is damn flexible.

Google Chart API

The quality of the charts is certainly good, with a clean API, easy to use and impressively fast response (it's evident that Google has resources to support it). The only problem we have is the limitation of 50000 API calls per-user. This might be tied to IP or accounts, and most likely using multiple ones to bypass the limit will get your access terminated. A solution to this problem is caching and limiting the requests, redirecting them to locally mirrored files if the information is recent enough or we have reached the API calls limit. While this works perfectly, it's not optimal for a commercial application.

PlotKit

The quick start guide shows a handful examples. The API makes use of a Layout and a Renderer that generates and inserts the chart in to the page content (using MochiKit), with a simplistic approach for introducing data-sets.
function drawGraph() {
    var layout = new PlotKit.Layout("bar", {});
    layout.addDataset("sqrt", [[0, 0], [1, 1], [2, 1.414], [3, 1.73], [4, 2]]);
    layout.evaluate();
    var canvas = MochiKit.DOM.getElement("graph");
    var plotter = new PlotKit.SweetCanvasRenderer(canvas, layout, {});
    plotter.render();
}
MochiKit.DOM.addLoadEvent(drawGraph);
The main disadvantage is that SVG and HTML CANVAS support have certain compatibility issues across different browsers and many still need to mature their support for such functionality. This leaves a huge surface of potential interoperability problems which might be a serious show-stopper when deploying PlotKit.

Dojo Charting

The feature-rich Dojo toolkit provides a neat charting library, supporting multiple charts per drawing area (or PlotArea). The data-set can be bound to a Store object (similar to the DataSource object of the YUI library), plus it supports all browsers except WebKit powered ones (those pesky Safari users! :) ). Some data analysis methods have been implemented too...

Dojo Charting: multiple charts in a PlotArea(s)

The usage is easy and documentation is very complete (something common with Dojo, probably due to its user base and support from several sponsors):
dojo.require("dojox.charting.widget.Chart2D");
dojo.require("dojox.charting.themes.PlotKit.orange");
dojo.require("dojox.charting.themes.PlotKit.blue");
dojo.require("dojox.charting.themes.PlotKit.green");
dojo.require("dojox.data.HtmlTableStore");
seriesB = [2.6, 1.8, 2, 1, 1.4, 0.7, 2];
dojo.require("dojo.parser");	// scan page for widgets and instantiate them
Note how HtmlTableStore is used and the Parser component. Within the HTML source:
<div dojoType="dojox.data.HtmlTableStore" tableId="tableExample" jsId="tableStore"></div>
<table id="tableExample" style="display: none;">
	<thead>
		<tr><th>value</th></tr>
	</thead>
	<tbody>
		<tr><td>6.3</td></tr>
		<tr><td>1.8</td></tr>
If there's something we appreciate from Dojo, it's the flexibility we enjoy from using it. You can certainly keep Dojo in mind for your charting (and several other UI) related needs. Regarding Internet Explorer support, as far as we know, several libraries make use of emulation for setting up HTML CANVAS support through VML.

Yahoo! UI (YUI) Charts Control

YUI Charts control example (Lines chart)

The amazing YUI library provides an experimental (as of version 2.4.0) Charts control with a nice API. The best thing about it: polling data from a DataSource object is supported. That means dynamic charts, easy interoperability and good performance. Rendering the charts is a piece of cake:
var mychart = new YAHOO.widget.LineChart( "chart", myDataSource,
{
	xField: "month",
	series: seriesDef,
	yAxis: currencyAxis,
	dataTipFunction: "getDataTipText"
});
YUI continues to impress us everyday. Since it uses Flash for rendering the charts, any browser with the Flash Player plugin will be able to render them. Also, the Flash charts can contain interactive labels and other useful details. This is clearly a winner in our books (and Dojo is always noteworthy too, but we can't afford using two toolkits since load times will skyrocket).

Thu, 06 Dec 2007

Annoyances of YUI when using custom styles

We've been coming across different annoyances in our quest of deploying YUI into one of our main products (a few more articles talking about its development coming soon), the Ruby on Rails content management system behind our almost-ready customer portal and corporate site. The problem comes mainly from the coexistence of our custom CSS and JavaScript code, and the YUI specific style-sheets and library files.

The problems are really bugging us and we have considered moving to fully custom code, even if that means delaying the development of some other features that might be of higher priority. Hopefully we will solve the issues soon and keep YUI in place, since the functionality is really complete.

Settings TabView gone wild!
Rich Text Editor doesn’t readjust its size…

Wed, 05 Dec 2007

New Yahoo! UI (YUI) library release! (2.4.0)

Yahoo! released yesterday a new version of the feature-rich, BSD licensed YUI (the Yahoo! User Interface library) implementing several improvements, some new controls and other innovative functionality. The components that quickly turned heads over here, are namely:

Their change-log contains a complete overview of the fixes and the new features. We are integrating this new release for the (Ruby on Rails powered) content management system engine we have developed for our corporate site, and recommend YUI for any serious web developer seeking a library providing solid controls and functionality. Besides, it comes with no strings attached.

Navigation

Archives

Syndication

Subscribe to our feed

Links

Send a tip

Meta

Powered by Python
Powered by (modified) Pybloxsom 100% free of PHP
Valid CSS!
Valid XHTML 1.0 Strict

License

Creative Commons License
Subreption blog by Subreption LLC is Licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.