Display data in Webcharts in ASP.NET 2.0 using Free Webchart control

In this article I will explain about how to display data in charts(eg: Area charts, pie charts,..) using Free chart control.

Before going to create chart in ASP.NET,you need to Download Free webchart control dll from http://www.carlosag.net/Tools/WebChart/.

To Create chart in ASP.NET open Microsoft Visual studio -> File
->New -> Website -> give name as ASPNETCHART and press ok.

Then Right click on Toolbox and select Choose Items and Browse for Webchart dll file and click ok.
Now you have to drag that chart control from Tool box to your source code.

The code in the code behind file look like below.

 
Imports WebChart Imports System.Data Imports System.Data.SqlClient Imports System.Drawing Imports System.Configuration Partial Class DisplayChart Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load BindToChart() End Sub Sub BindToChart() Dim sqldad As SqlDataAdapter, ds As New DataSet Dim sqlcon As New SqlConnection("Connectionstring") Try sqldad = New SqlDataAdapter("select date,salary from salaries with (nolock)", sqlcon) sqldad.Fill(ds) Dim chart1 As New StackedColumnChart chart1.DataSource = ds.Tables(0).DefaultView chart1.DataXValueField = "date" chart1.DataYValueField = "salary" chart1.DataLabels.Visible = True chart1.DataLabels.ForeColor = System.Drawing.Color.Blue chart1.Shadow.Visible = True chart1.DataBind() 'chart1.Explosion = 10 ChartControl1.Charts.Add(chart1) ChartControl1.RedrawChart() Catch ex As Exception Response.Write(ex.Message) End Try End Sub End Class

In the above code we are displaying the database table data using StackedColumnChart.
You can display data in many other formats also like Line Charts, Smooth Line Charts, Column Charts, Area Charts, Scattered Charts, Stacked Column Charts, Pie Charts and Stacked Area Charts.

To get complete idea about this webchart control visit http://www.carlosag.net/Tools/WebChart/ .
This webchart control is absolutely free and it is not trial control. You can use this control where ever you want to display data in chart format.


Download source code here