Dynamically adding new series to chart

Thread is closed for posting
2 posts, 0 answers
  1. Paul
    Paul avatar
    76 posts
    Member since:
    Feb 2008

    Posted 18 Nov 2009 Link to this post

    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!
  2. Paul
    Paul avatar
    76 posts
    Member since:
    Feb 2008

    Posted 19 Nov 2009 Link to this post

    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.
Back to Top