There are two ways of creating charts using ASP.NET charting control: at design time or at run time, creating charts at run time makes more sense as interface and logic are separated. In this implementation we would be creating a Bar Chart at design time and Line chart at run time. To add Bar Chart add following code to 'Default.aspx':
Every chart has a number of elements, all these elements are available via Chart control. The above code shows some basic elements of chart control, every chart has atleast one 'Series' object populated with data. 'ChartType' property of series determines the type of chart i.e Line, Bar etc. 'ChartArea' is a rectangular area used to draw series, labels, axes, grid lines, etc. On the other hand to create Line Chart on run time, add the following code to 'Default.aspx.cs':
using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.DataVisualization.Charting; namespace TestCHART { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
Series series = new Series("Spline"); series.ChartType = SeriesChartType.Spline; series.BorderWidth = 3; series.ShadowOffset = 2; series.Points.AddY(60); series.Points.AddY(90); series.Points.AddY(20); Chart1.Series.Add(series); } } }
The co-ordinate system of chart control is a relative means for chart objects to remain relative to each other when chart is resized, thus making the positioning easier. Origin of coordinate system is in the upper left corner with X axis pointing right, Y axis pointing down, and Z axis (for 3D charts) pointing outwards. Besides the chart implemented in this article there are plenty of other chart types available, one can also bind data to chart using Data Source Configuration Wizard, just select ''from drop down window in front of 'Choose Data source' and define data source i.e. SQL database.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.