ASP.NET charts example: Odin Sphere: Part 1 - Introduction and model

For a while now I've been meaning to work with ASP.NET 4's built-in charting functionality. While I was going to use it alongside my gas tracking, I think I'm instead going to use my Odin Sphere leveling guide, so I don't have to create an XSLT for the output.

In this part of the series I'll outline the data model I'll be using, and preliminary setups.

Method

So that this can easily be deployed anywhere, I'm going to opt not to use the control itself, but rather programmatically create the charts/graphs. I'll be creating a generic handler (.ashx) to handle the output.

I'll be using LINQ to XML to query the XML file that stores the content and may implement some level of caching at some point.

My environment is Visual Studio 2010 and .NET Framework 4. The controls are available for 3.5 and 2008, however, and 2010 Express should also suffice.

Data model

For this chart I'd like to chart each character's HP progression as they level, with each character displaying on the same graph.

This then gives us a List of Character, with each Character having a Name and a List of HpLevel, with HpLevel containing a Level and a HP total.

In our new Generic Handler (OdinSphere.ashx) we'll add the following within the existing public class:

	/// <summary>
	/// One of the five playable characters in Odin Sphere, for the Playstation 2.
	/// </summary>
	public class Character {
		/// <summary>
		/// Name of the character.
		/// </summary>
		public String Name { get; set; }
		/// <summary>
		/// List of hit point leveling information.
		/// </summary>
		public List<HpLevel> HpLevels { get; set; }
	}
/// &lt;summary&gt;
/// Hit point information at a particular level.
/// &lt;/summary&gt;
public class HpLevel {
	/// &lt;summary&gt;
	/// Level of the character.
	/// &lt;/summary&gt;
	public int Level { get; set; }
	/// &lt;summary&gt;
	/// Hit points at a level, for a character.
	/// &lt;/summary&gt;
	public int HitPoints { get; set; }
}</code></pre>

These also require the following:

using System.Collections.Generic;
using System.Linq;

At this point we've got our objects defined and set, so we can grab the data from the XML file and create our necessary objects ... which is exactly what we'll do in the second part of this series.