Click here to Skip to main content
16,021,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to display more than one series on a line chart. I'm producing a resultset from a stored procedure which is like this:

Type Value Date

TypeA 0.07 01/06/2006

TypeB 0.08 01/06/2006

TypeC 0.08 01/06/2006

TypeA 0.08 02/06/2006

TypeB 0.09 02/06/2006

TypeC 0.09 02/06/2006

TypeA 0.09 03/06/2006

TypeB 0.10 03/06/2006

TypeC 0.11 03/06/2006

I want a seperate series for each of TypeA, TypeB, TypeC . Is it possible to doctor the resultset to give each Type (and Value) as unique columns? Or is there another way?

Thanks in advance for any help.
Posted

1 solution

yes you can very much do it in many ways...
1) you can add multiple series (of type line in your case) on one chart area and you can loop thru your records and add data points to those series based on your type (use switch statement), i personally like to do it as below so that you can also customise various labels, apply diff. type of chart on series etc....

<br />
 Series sA = new Series("Type A");<br />
    sA.ChartType = SeriesChartType.Line;<br />
 Series sB = new Series("Type B");<br />
    sB.ChartType = SeriesChartType.Line;<br />
 Series sC = new Series("Type C");<br />
    sC.ChartType = SeriesChartType.Line;<br />
loop thru your records here {<br />
DataPoint p = new DataPoint();<br />
switch(type){<br />
case 'TypeA':<br />
// add data point to series 'A'<br />
 p.SetValueXY() // set your values here<br />
sA.Points.Add(p);<br />
case 'TypeB':<br />
// add data point to series 'B'<br />
.....<br />
}<br />
}<br />
yourchart.Series.Add(sA);<br />
yourchart.Series.Add(sB);<br />
yourchart.Series.Add(sC);<br />


2) another way would be to do it by making and ienumerable type of your retrieved data (something like dictionary) and then bind or cross bind your datatable to these charts
do read this to know how you can directly bind the data to the chart:
http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
This is a very nice explanation of databinding to charts, the third onwe is exactly your scenario

hope this helps.
 
Share this answer
 
v4
Comments
Member 7666785 20-May-11 5:47am    
THANKS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900