SIGN UP MEMBER LOGIN:    
ARTICLE

MSChart : How to Draw a Line or Multiple Line Charts

Posted by Suthish Nair Articles | Office Development August 19, 2010
This article shows how to draw a line chart or multiple line charts using MSChart.
Reader Level:
Download Files:
 

Getting Started

This article shows how to draw a Line or Multiple Line Charts using the MSChart control and also applying some important properties like Tool Tip, Legends, Line width, Shadow, 3D etc. A simple SQL Script which returns output for Category wise UnitPrice details which are plotted on a Chart Control. The sample code attached project was made using VS 2010 with the SQL Script. The project contains two web pages with samples of Single Line Chart and Multiple Line Charts. Prerequisite: VS 2008/2010, SQL Server.

References used

img1.gif

Code Explained
 
Drag and Drop a Chart control onto the page and set the Width and Height.

img2.gif

SingleLineChart.aspx.cs

On Page Load an SQL Connection is made and using SqlDataReader data is get fetched from database.

If any rows are found, then the chart is plotted by creating a Chart Area, Series and plotting points for Series. 

img3.gif
  1. Creating a ChartArea, it's the primary placeholder for plotting a chart.
  2. Creating a Series, used as a placeholder for the data points to get plotted on the chart.
  3. The Series Chart type must be a Line Chart.
  4. Points are plotted on a Series using the DataBindXY method by passing Column names and values to respective X and Y Axis of Chart, thus plotting the graph.
img4.gif

MultipleLineCharts.aspx.cs

Using two different SQL scripts and plotting two different Line Charts. For plotting multiple chart types we need to create multiple Series also on a single Chart Area.

img11.gif

The output will be as below.

 
img6.gif
 
Some Important Properties
  • Setting Chart border and BackColor.

img7.gif

  • Setting Chart Area X and Y Axis values, enabling 3D etc.

img8.gif

  • Legend Properties

img9.gif

  • Show Series data points as Label text, ToolTip, set border width and Line color.

img10.gif

Conclusion

This article shows how to draw a Line chart or Multiple Line Chart by using MSChart. Hope you all liked it; the sample code is attached for download and testing the code. Post your comments and rate the article. Post your queries to our Forum Section.

Login to add your contents and source code to this article
share this article :
post comment
 

Useful article..Thanks

Posted by fousia pa Apr 16, 2012

nice post

Posted by ramarao ullapaneni Jan 21, 2012

Thank You!

Posted by Suthish Nair Aug 01, 2011

Very Nice Article...........

Posted by Angelina Erin Aug 01, 2011

article re-written

Posted by Suthish Nair Jul 31, 2011
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor