Sparklines in .NET Applications

One of things we spent a good deal of time on Friday in the Tufte seminar was his concept of “Sparklines”. Tufte describes them as “Intense, Simple, Word-Sized Graphics”. The idea is that a small (very small) chart of information can be provided in-line with text and serve to illustrate the data behind the text. In the space consumed by just a few words, hundreds (even thousands, with sufficient resolution) of data points can be used to form a chart.


In explaining Sparklines in Beautiful Evidence, Tufte uses several examples. One of these is medical reports that typically provide a test name and then the result value as a number. What this loses, however, is the context for the measurement — is this result high or low relative to the patient’s history? Relative to the normal range?


SparklinesThe image at right shows several examples. First is the typical display for a glucose test’s result (128). The second is a sparkline example that shows the patient’s results over time. In this context, it’s clear that the result of 128 is low relative to many of the patient’s previous results. The third example places a red dot at the point of 128 (the most recent result) and then displays the result value text in red, instantly drawing a correlation between the point on the chart and the value at that point. The bottom example combines a light gray band representing the normal range. The result is a graphic that quickly provides context and history for a test result, using much less space than the text “relatively low for this patient and within normal range” would require.


So can we use Sparklines in applications? First, we certainly are allowed to use this concept. Tufte himself referred to it as an “open-source idea to be freely used”. Next, the question is, how do we use this in our applications?


In searching around for software implementations of Sparklines, I found several. There are implementations for PHP, Java, Ruby, Python, MS Office, and others. Note that the Python implementation, written by Joe Gregorio, is provided online as a “Sparkline Generator Web Application”. It’s a slick interface that lets you fill out a form to set some properties and values, and then provides the URL that would return the resulting Sparkline.


I also found a .NET implementation from Eric Bachtal. He implemented it last year as an HTTPHandler for ASP.NET applications. The results look great on a web page and the code is provided with a license to freely use, copy, modify, and so on. 


For me, I’d like the ability to use this in a couple other ways. First, I’d like a general object API that lets me set some properties (style, colors, size, etc), provide the data, and then get an Image type in return. From there, I’d like to see a control that can be used in a Winforms application — either directly on a form or within a data grid, with the ability to resize and adjust like any other UI control. While the license indicates that it’s fine, I plan to contact Eric to see if he minds me using his work to get a leg up on that effort. I’ll report back here when/if I make progress.


Definitely check out the various examples and libraries above. Each appears to be free for personal use and all but one makes the source available in some form. The MS Office product from Nicolas Bissantz requires purchasing a license for commercial use and no source is provided, but it’s also the most friendly to non-developers and several Sparklines-inspired products are available (including a cool ticker).