Configuring the chart object is a two-step process. The first step is to set the cosmetic properties of the chart as defined in the configuration file. The second is to load the data into the chart.
The CallCharter function (Listing 2) achieves this. It parses the configuration file to get a chart type and then builds a chart according to the <TYPE> setting in that file.
This function is easily expanded to allow the user to add new settings to the configuration XML file and have them parsed, effectively exposing the property model of the charting engine (in this case Microsoft OWC) to a user via a properties file.
At present, the configuration is quite simple, only the chart type, background and foreground colors, and the legend position are configurable.
The CallCharter function loads the data to the Charting engine, as specified in the XPath variables, with the following lines:
xNodeList = xmlSource.SelectNodes(strXPath)
xCatsNodeList = xmlSource.SelectNodes(strCategories)
These create the nodelist from the XPath variables that have been sliced out of the configuration document. It then walks through these NodeLists, creating a string array that gets loaded by the OWC, which recognizes this data structure for adding data series and data categories.
|Figure 3: Sample Bar Chart. This bar chart is built up using an XPath where only players whose position is DEF or DEF-MID have their overall points plotted.
In addition to the pie chart shown above, I've provided two other examples of charts that were built with the charts.xml file included in the download (see Figures 3 and 4). You can add your own charts easily by amending this file.
You can modify the chart server to accept URL-driven data services. See the sidebar "Expanding the Functionality."
The revolution in data interchange brought about by XML has only just begun. New technologies are emerging every day that allow us to think about the information that we need in new and exciting ways. XPath, a simple innovation, has opened up new realms of possibility for automatic use of this data. This chart server is just a simple example of some very exciting things to come.