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

Chart Series Colors not Changing

1 Answer 19 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Marcio Nascimento
Top achievements
Rank 1
Marcio Nascimento asked on 24 Jul 2012, 01:07 PM
Hi,

I have two line series.I set the first serie color to BLUE, then I set the second serie color to RED.
I don't know why the second serie always appear BLUE. I think this might be simple but I can't visualize the solution.
Can anyone help? The code Follows below:

private void PopulateChart3(string seriesID)
{
    RadChart1.Clear();
    SapeDBDataContext db = new SapeDBDataContext();
 
    int ID = Convert.ToInt32(seriesID);
    var windh = from p in db.SAPE_WindSeries where p.id_localidade == ID where p.valorh != null select p;
    var windp = from p in db.SAPE_WindSeries where p.id_localidade == ID where p.valorp != null select p;
 
    ChartSeries s = new ChartSeries();
    s.Type = Telerik.Charting.ChartSeriesType.Line;
    s.Appearance.LabelAppearance.Visible = false;
    s.Name = "Historic";
    s.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.Blue;
 
    foreach (var wi in windh)
    {
        ChartSeriesItem item = new ChartSeriesItem();
        item.XValue = Convert.ToInt32(wi.dia);
        item.YValue = Convert.ToDouble(wi.valorh);
        s.Items.Add(item);
    }
 
    ChartSeries s2 = new ChartSeries();
    s2.Type = Telerik.Charting.ChartSeriesType.Line;
    s2.Appearance.LabelAppearance.Visible = false;
    s2.Appearance.LineSeriesAppearance.Color = System.Drawing.Color.Red;
    s2.Name = "Projected";
     
 
    foreach (var wi in windp)
    {
        ChartSeriesItem item2 = new ChartSeriesItem();
        item2.XValue = Convert.ToInt32(wi.dia);
        item2.YValue = Convert.ToDouble(wi.valorp);
        s.Items.Add(item2);
    }
 
    RadChart1.Series.Add(s);
    RadChart1.Series.Add(s2);
}

Thanks,

Marcio Nascimento

1 Answer, 1 is accepted

Sort by
0
Maxime
Top achievements
Rank 1
answered on 25 Jul 2012, 08:41 AM
Hi Marcio,

Inside both of your foreach loops, you add the item inside the "s" serie, and not "s2"

Actually, you don't have any data inside your "s2" serie. Your second loop must be like this in order to achieve what you want :
foreach (var wi in windp)
    {
        ChartSeriesItem item2 = new ChartSeriesItem();
        item2.XValue = Convert.ToInt32(wi.dia);
        item2.YValue = Convert.ToDouble(wi.valorp);
        s2.Items.Add(item2);
    }
Tags
Chart (Obsolete)
Asked by
Marcio Nascimento
Top achievements
Rank 1
Answers by
Maxime
Top achievements
Rank 1
Share this question
or