Experience Report: Creating SVG Pie Charts through XSLT via a Web Service

Like many IT departments, the Federal Reserve Bank of New York’s is under pressure to cut costs. IT also needs to show the value it provides — to justify the costs that are not cut. This report describes an effort that combined both these dimensions, an effort to cut costs in demonstrating the value we provide.

IT at the Fed, like other departments, produces plenty of reports with graphical content. Our graphics show, for example, how many people from other Bank areas use our services, and how our costs are distributed to those areas. Content providers generally use different proprietary tools in generating graphics, and tend to start from scratch each time.

We realized that SVG would avoid the cost of proprietary tools — not only the costs of acquisition and maintenance, but also the costs of learning tools that are certain to be abandoned. On the other hand, we were not prepared to ask our content providers to master SVG. While our content providers have different degrees of technical adeptness, proprietary tools attract them, in part, through their ease of use. Writing SVG in Notepad does not provide ease of use.

Most of the graphs we produce, though, are not new types, but simply new instances of familiar charts. We thought that we’d be able to build the basic graphs in advance, and then ask content providers only for the particular data from which the instance would be drawn. We would create a Web service that takes XML data, transforms it through XSLT, and creates an SVG graphic. We’ve now completed this for one type of graphical object, a pie chart.

The report begins with examples of the XML that a content provider supplies. While XML can intimidate some at first, its creation does not require any technical skills, and we provide a simple schema to follow. The report continues with the set of XSLT transformations that create pie charts in response to these validly constructed XML files. The transformations incorporate best practices for pie charts, such as having the largest meaningful slice begin at the positive vertical axis of the pie, moving counterclockwise, and aggregating small contributors into an ‘other’ slice. I provide and describe the XSLT code that implements these practices and creates the pie charts.

Even with the XSLT set, we could not ask our non-technical users to install Xalan and run the transformations themselves. We decided to offer them as a Web Service. We could have offered them in other ways, but chose Web Services both to gain experience in their use and to prepare for the future we expect. Since we anticipated that this Web Service would be called mostly through human interaction, we also created a Java servlet to serve as a client.

Moving the Xalan invocation from command lines to Java code actually simplified the process. For programming ease, I had decided that the transformation should be done in three separate steps, with two interim files. I stored these interim files on disk when using Xalan from a command line. When the steps were called from a Java routine, though, I could store the interim files in memory. I provide and describe the code for this and for the Web Service clients.

All the processes in this effort rely on open source software and specifications. Other than Java, the software is from the Apache foundation — Xalan, Soap, and Jakarta Tomcat. The specifications are from the W3C — XML, XSLT, and SVG. For the pie chart, I started with examples others offered on the Web.