ASP.NET Bar Chart Graph
Online Demo
This script generates a series of horizontal bars in graph chart format, on an .aspx web page.
To run the graph script is very simple. First save the following code into a file called dotnetgraph.ascx
Then save the following in the same directory to a file called dotnetgraph.aspx
|
Select All Code
|
|
Within this aspx page you will see we set all the quantities and labels for the graph within the Page_Load function.
There is obviously plenty of scope for development in this section - for example, pulling these values directly from a database. But hopefully the elegant simplicity of these files will be a useful introduction to the concepts involved.
Added by the author
I was still a little new to .NET when I wrote this article two years ago
, so there are a couple things I'd change if implementing now:
1. Use StringBuilder instead for the RenderItem method:
private String RenderItem (Int32 iVal, Int32 iMod, String sColor) {
StringBuilder sb = new StringBuilder();
sb.Append("<table border=0 bgcolor=" + sColor + " cellpadding=0 cellspacing=0><tr>");
sb.Append("<td align=center width=" + (iVal * iMod) + " nobr nowrap>");
sb.Append("<b>" + iVal + "</b>");
sb.Append("</tr><td></table>");
return sb.ToString();
}
StringBuilder is orders of magnitude faster than manipulating strings directly (strings are immutable).
|
|