Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Serve Business Graphics from Any XML Source : Page 2

Using the flexibility afforded by defining data in XML and parsing it with XPATH, you can develop a decoupled VB.NET application that serves up business graphics.


advertisement

Most charts can be broken down into a series of common objects, the two most important of which are data series and data categories. A data series is just what it sounds like—a series of data which are to be plotted together forming a relationship. For example, in the case of a line chart, the data series are the points in the line; in a pie chart, the data series are the quantities that make up the size of the 'slice' of the pie. Data categories on the other hand are the points that describe the data series. For example, in a line chart, if the data series are stock closing prices, the usual data category to match these data would be the dates on which the stock closed at those prices.

The samples in this document are based on an XML document containing the season statistics for the New York Power womens' soccer team. Click hereto view this document.

In the example below, the points scored by the players has been charted as a pie chart. The points compose the data series, the players' names compose the categories.

 
Figure 2: Sample Pie Chart In this pie chart (generated by this application), the data series are the points that each player scored, and the data categories are the players' names.



Some charts require multiple data series, for example charts where you want to compare two sets of data such as Earnings Estimates vs. Real Earnings, or games played vs. points scored.

Building a Chart
The chart server that you are going to build processes an XML document as in Figure 1above, reading the XPath values for the series and categories and applying them to the document to create internal data structures representing the data series values and the data category values. It then builds the chart object using these as its parameters.

These values, along with other configuration information for each chart are stored in a charts.xml file. The section within this file that builds the chart in Figure 2is shown here:


<chart id="points">
  <url>http://localhost/players.xml</url> 
  <config>http://localhost/pmconfig2.xml</config> 
  <series>//Players/Player[Points>0 and Minutes>1000]/Points</series> 
  <categories>//Players/Player[Points>0 and Minutes>1000]/Name</categories> 
  <XSize>600</XSize> 
  <YSize>400</YSize> 
</chart>

This tells the server where the data source for the chart is hosted, where the configuration for the chart is hosted, and what the XPaths are for the data series and the data categories. As you can see, the XPath values can be quite sophisticated, in this case filtering the document down to all Players who have some points and who have played more than 1,000 minutes. Their points make the data series and their names make the categories.

At present, the configuration file for an individual chart contains settings for the chart type, the chart title, the category title, the values title, and the title for each series. This could easily be expanded to allow the colors of the data series to be defined instead of hard coded.


<chart>
	<Type>1</Type>
	<Title>Points By Player</Title>
	<CatTitle>Player Name</CatTitle>
	<ValTitle>Points</ValTitle>
	<SeriesTitles>Points Scored</SeriesTitles>
</chart>

How the Application Works
The Page_Load function (Listing 1) grabs the parameters (chart, width, and height), loads the configuration XML file, parses it to get the correct data document, and sets up all the variables that are required by the CallCharter function (Listing 2), which performs the actual charting.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date