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


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.

- Creating a ChartArea, it's the primary placeholder for plotting a chart.
- Creating a Series, used as a placeholder for the data points to get plotted on the chart.
- The Series Chart type must be a Line Chart.
- 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.

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.

The output will be as below.

- Setting Chart border and BackColor.

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

- Legend Properties

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

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.


Javed AlamPosted Sep 13, 2018, 12:52 AM EDT
Very nice..
Sandy SingPosted Jul 29, 2018, 8:11 PM EDT
It is not showing all category name ? can you tell me how can i resolved it
krishantha de silvaPosted Mar 14, 2018, 7:52 PM EDT
It is not work properly, it only draw two vertical line from edge of the chart pls help me to solve this problem
Akshaya arumugamPosted Feb 19, 2018, 2:56 AM EST
Oh great and nice I need to a comparison between 2 series take it data from SQL tables with c# windows form, can help me?
Sagar Pandurang KapPosted Dec 25, 2017, 11:13 PM EST
Nice tutorial.Well done..
Dinesh SanthalingamPosted Dec 19, 2016, 9:55 PM EST
Thanks for your article.great work.
Marwa MohammedPosted Dec 2, 2016, 8:29 AM EST
I need to comparison between 2 series take it data from sql tables with c# windows form,can help me?
Seethalakshmi BPosted Oct 9, 2015, 10:12 PM EDT
Good one
SandyPosted Jun 18, 2014, 1:52 AM EDT
great article
Dino GPosted Nov 12, 2013, 1:45 AM EST
Thanks 4 ur code
ali mohammadiPosted Nov 1, 2013, 1:32 PM EDT
tanx your code was very helpfull for me
cenkPosted Jul 5, 2013, 3:59 AM EDT
Thank you so much
avinash sahuPosted Mar 21, 2013, 6:55 AM EDT
great
Suthish NairTOP 100Posted Jan 8, 2013, 9:15 AM EST
:)
mathan kumarPosted Jan 7, 2013, 2:23 AM EST
sry. i was make some problem in my DB. Your code executed successful. thanx
mathan kumarPosted Jan 4, 2013, 1:16 AM EST
but some dll was missing
mathan kumarPosted Jan 4, 2013, 1:15 AM EST
thanx. it was very useful for me!
JOHN fooeditedPosted Dec 18, 2012, 4:13 AM ESTEdited Dec 18, 2012, 4:14 AM EST
it cant run properly cos dun hav the database
kiran ghugeeditedPosted Dec 3, 2012, 2:12 AM ESTEdited Dec 3, 2012, 2:22 AM EST
your article is most helpful but i have one query regarding chart i.e i have 10 column and i want to show all column on X axis but i can show only 9 column when i increasing 10th column odd number of column get disappear and only even number of column appear.sir can you please help me in this Thanks and regards Kiran Ghuge [email protected]
vivek meshramPosted Oct 15, 2012, 2:54 AM EDT
helpful article ,what i want i got...thanks a lot sir..
fousia paPosted Apr 15, 2012, 8:00 PM EDT
Useful article..Thanks
ramarao ullapaneniPosted Jan 21, 2012, 1:19 AM EST
nice post
Angelina ErinPosted Jul 31, 2011, 8:34 PM EDT
Very Nice Article...........
Suthish NairTOP 100Posted Jul 31, 2011, 1:07 PM EDT
article re-written
Scott BrownPosted Sep 21, 2010, 12:37 PM EDT
Suthish, The second post that you have there is exactly what i was looking for. Thank you very much for posting. Scott
Suthish NairTOP 100Posted Sep 20, 2010, 6:18 AM EDT
Hi Scott, There is no direct way in displaying the tables. refer article, shows legends plot.. http://www.c-sharpcorner.com/UploadFile/suthish_nair/3420/?ArticleID=88a98858-b5e3-477b-8a63-c168bb53681b Another way, is using a Grid View. Let me try, if got will share here..
Scott BrownPosted Sep 13, 2010, 9:02 AM EDT
I need to show a data table at the bottom of my graph. Like the following: Jan Feb Mar Series 1 2.0 1.0 1.5 Series 2 3.0 2.1 2.1 Series 3 2.0 3.5 4.0 Any Ideas? I can get the table to show the Values on the right (Series 1, Series2, Series3). Thanks for the great article!