Charting in ASP.Net 4.0

Charting is one of the new features introduced in ASP.Net 4.0. In the earlier versions of ASP.Net and the .NET Framework, constructing a chart required the use of graphics and other complicated stuff. There were ways to use external controls and DLL files (either free or from a third-party vendor) for charts. To make it simple and avoid third-party vendors, Microsoft introduced its own chart control in ASP.Net 4.0.

Expand the Data area in your toolbox. You can see the chart control. This allows making your customers requesting data information happier by adding a chart to them based on the statistics.



Double-click on it or drag and drop the chart control to your designer.



In the designer, it looks like this.



The series section creates the Blue colour columns. We can have more than one series.

If we have more than one series, the chart will look like the following one.





Let us proceed with a simple example with one series.

Let us create a datatable that has team and team strength.

I have used the following ADO.Net code. If we wrap this up in a method, it goes like:


In the page load:



This generates a chart like this:


To add labels to the x and y axis use the following code.



The final output will be like the following one. I have used a custom font and graphics for printing the final Mars WebCC line.


This is a very simple example with charts and we can also bind our charts from a database. There are things like Legends, Annotations, and so on we can add to these charts.

Let me provide you an update about this in my future posts.

Thanks.


Recommended Free Ebook
Similar Articles