.netCharting

Improve Your Image

Steve C Orr

October 30, 2009

6 Min Read
ITPro Today logo

asp:review

 

.netCharting

Improve Your Image

 

By Steve C. Orr

 

They say a picture is worth a thousand words. Sometimes achart can clarify complex data into crystal clear results like nothing elsemedia can. While few people would dare to argue this point, there is plenty ofroom for debate about the best way to generate such charts. One way to createsome basic charts is by using HTML (asp.netPROsubscribers may access Orr s article BarGraphs to Go). Another technique is to let Excel generate such charts foryou (asp.netPRO subscribers mayaccess Orr s article Exportto Excel). Yet another common technique is to use the System.Drawingnamespace of the .NET Framework to harness the power of GDI+ (asp.netPRO subscribers may access DinoEsposito s article BuildDynamic Web Charts). Although you can generate gorgeous charts with thelatter technique, it can be quite time consuming to do so. If you need chartsthat dazzle the eye, the most cost-effective solution is usually to buy a third-partycomponent to help out. And I must say, .netCharting generates some of the mostvisually stunning charts I ve ever seen.

 

Getting Started

After downloading the free demo, you ll discover theinstallation process is fairly manual. You must establish the samples folder asan IIS application if you want to view the charting examples in action. To addthe component to one of your own Web applications, you must copy the includedDLL into your bin folder, make a reference to it from within Visual Studio.NET,and add it to your toolbox. You must then create a temporary folder and givethe ASPNET worker process write access to this folder so that the component hasa place to send the charts it generates. These steps should be familiar toexperienced Web developers; however, the process could be a bit much forbeginners to swallow. In my opinion, a more automated installation option wouldbe a welcome addition to a future version of the product.

 

There is so much sample code that it s almostoverwhelming. No matter what kind of chart you want to create, you ll certainlybe able to find a code snippet that can be modified for your needs. All codesamples are provided in both C# and VB.NET. The documentation is thorough andcomplete, providing detailed explanations for every property and methodavailable in the object model.

 

Simple Implementation

It only takes a few lines of code to create a basic chart.To configure your chart you can use code such as this:

 

Chart1.Title = "My Chart"

Chart1.Use3D = True

Chart1.DefaultSeries.Type = SeriesType.Cylinder

Chart1.TempDirectory = "temp"

Chart1.Size = "640x480"

 

The first line (obviously) sets your chart title, and thesecond line configures the chart to appear in 3D, which is usually morevisually appealing than 2D. The third line sets the bars in this chart toappear cylindrical instead of as plain old rectangles. The temp directory needsto be set to tell the control where to write the chart. As mentionedpreviously, the ASPNET user account needs write permissions to this temp directory.Finally, the size of the chart is set. Alternatively, these properties (andmany others) can be set at design time.

 

The chart can be bound to DataSets, DataTables, DataViews,DataReaders, XML, and even Excel files. Alternatively, you can programmaticallygenerate the data by using series and element metaphors that should be at leastvaguely familiar if you ve used any kind of charting product before. Whencombined with the code in Figure 1, the previous code creates the output shownin Figure 2.

 

'Load some data

Dim SC As New SeriesCollection

Dim s As New Series

Dim el As Element

el = New Element

el.Name = "7/1/2004"

el.YValue = "202"

s.Elements.Add(el)

el = New Element

el.Name = "7/2/2004"

el.YValue = "201"

s.Elements.Add(el)

el = New Element

el.Name = "7/3/2004"

el.YValue = "200"

s.Elements.Add(el)

el = New Element

el.Name = "7/4/2004"

el.YValue = "198"

s.Elements.Add(el)

SC.Add(s)

Chart1.YAxis.Minimum = 190

SC(0).Elements(0).Color = Color.FromArgb(49, 255, 49)

SC(0).Elements(1).Color = Color.FromArgb(255, 255, 0)

SC(0).Elements(2).Color = Color.FromArgb(255, 99, 49)

SC(0).Elements(3).Color = Color.FromArgb(0, 156, 255)

Chart1.SeriesCollection.Add(SC)

Figure 1: Whiledatabinding is a good option, chart data can also be generated programmatically.

 


Figure 2: Beautiful charts takelittle effort.

 

Dozens of chart types can be created. Of course, all thestandard types such as bar graphs, pie charts, and line graphs are supported. Inaddition, many less common chart types are also possible, such as bubblecharts, candlesticks, radar graphs, area charts, and even gauges that wouldlook at home on the dashboard of your car. For most chart types there aredozens of properties that can be set to widely vary the output. Figure 3demonstrates that you can even combine a mixture of chart types to createvirtually any chart you can dream up.

 


Figure 3: Different chart types canbe combined into a single chart, unleashing virtually unlimited possibilities.

 

Function and Form

The beauty in these charts is more than skin deep. Notonly are they attractive, but they provide rich functionality, as well. Built-indrill-down capabilities allow you to click on different chart elements (such asa specific bar in a bar chart) to display a new chart that dissects the dataeven further. For example, if your user wants to know why 2003 sales were somuch higher than 2002, they can click on the 2003 bar to get a breakdown bymonth. If your data supports it, they can then drill down further into dailyfigures and beyond.

 

Charts can be automatically cached, and stale charts canbe automatically purged to free hard drive space on the server. Annotations canbe added anywhere on the graph, or attached to any chart element in virtuallyany position imaginable. Tooltips can appear over any chart element to bring upadditional data details for curious users. Legends can be configured in manyflexible ways, including being rendered as a separate image so you can place iton another area of the page. Colors, symbols, and hatch styles can be adjustedto suit all users, including disabled users and users of mobile devices withlimited display capabilities. In case you can manage to think of a chart that.netCharting won t fully create, PostRenderDrawing can be used to allow you topaint on the final details yourself.

 

The Price Is Right

Pricing starts at around US$400, and support optionsinclude an online knowledge base and e-mail technical support. There are avariety of no-nonsense licensing options available, including unlimiteddevelopment servers, unlimited users, or unlimited CPUs for a given server. Nomatter which licensing option suits you best, you ll have the fullfunctionality of the product at your disposal, as there are no annoying Professional or Enterprise versions of the product that unlock special functions forhigher-paying customers.

 

Sure, you could create all this functionality yourself givenenough time. After all, this product was developed purely in C#. However, $400worth of your time could only create a fraction of the functionality includedin this product, so you may want to give this product some seriousconsideration before embarking on your next charting project.

 

Steve C. Orr is anMCSD and a Microsoft MVP in ASP.NET. He s been developing software solutionsfor leading companies in the Seattlearea for more than a decade. When he s not busy designing software systems orwriting about it, he can often be found loitering at local user groups andhabitually lurking in the ASP.NET newsgroup. Find out more about him at http://Steve.Orr.net or e-mail him at mailto:[email protected].

 

Rating:

Web Site: http://www.dotnetcharting.com

Price: Startsaround US$400

 

 

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like