This is a migrated thread and some comments may be shown as answers.

Dynamically adding new series to chart

1 Answer 320 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 18 Nov 2009, 06:14 PM
I have a bar chart that I am binding to data collected at run-time. I need to be able to add a series of line charts to the chart but I'm having a hard time getting them to appear.

In my code below I am getting some data using linq and binding it to my chart. I then want to add a line series to the chart to represent a target (For eample my chart shows test scores for a group of students using a bar chart and I want to add a line across the 80% mark to represent a target score) How would I go about doing this?

I tried:
var ReopenRate = from myRow in dtTSEdata.AsEnumerable()  
                 orderby myRow.Field<int>("tm_join") descending  
                 select new { name = myRow.Field<string>("ln_fi"), value = myRow.Field<System.Nullable<double>>("reopen_rate") };  
 
 
RadChart1.DataSource = ReopenRate;  
RadChart1.DataBind();                      
RadChart1.Series[0].DefaultLabelValue = "#Y{P1}";  
RadChart1.Series[0].PlotArea.YAxis.Appearance.CustomFormat = "P0";  
 
// attempting to add line series to chart
ChartSeries csud = new ChartSeries();  
csud.Type = ChartSeriesType.Line;  
csud.AddItem(80, "Target", System.Drawing.Color.Red); 

I have also tried a few other ways unsuccessfully and I haven't been able to find any examples. There must be something I am missing.

By the way, my bar chart is displayed horizontally and I would like the line to run vertically (I.E. at the 80% mark).

Thanks!

1 Answer, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
answered on 19 Nov 2009, 03:38 PM
I solved my own problem.. Just in case someone else needs this info:

var ReopenRate = from myRow in dtTSEdata.AsEnumerable()  
                 orderby myRow.Field<int>("tm_join") descending  
                 select new { name = myRow.Field<string>("ln_fi"), value = myRow.Field<System.Nullable<double>>("reopen_rate") };  
 
RadChart1.DataSource = ReopenRate;  
RadChart1.DataBind();  
RadChart1.Series[0].Type = ChartSeriesType.Bar;  
RadChart1.Series[0].DefaultLabelValue = "#Y{P1}";  
RadChart1.Series[0].PlotArea.YAxis.Appearance.CustomFormat = "P0";  
 
// dynamically create a new series
ChartSeries csTarget = new ChartSeries();  
for (int i = 0; i < dtTSEdata.Rows.Count; i++)  
{  
    csTarget.AddItem(.8);  // adds the same value for each row
}  
csTarget.Type = ChartSeriesType.Line;  
                      
RadChart1.AddChartSeries(csTarget);  
RadChart1.Series[1].DefaultLabelValue = ""

This displays a bar char which displays a "score" for each person and the second series adds a line across the 80% mark.
Tags
Chart (Obsolete)
Asked by
Paul
Top achievements
Rank 1
Answers by
Paul
Top achievements
Rank 1
Share this question
or