Chart Series Colors not Changing

Thread is closed for posting
2 posts, 0 answers
  1. Marcio Nascimento
    Marcio Nascimento avatar
    54 posts
    Member since:
    Jul 2009

    Posted 24 Jul 2012 Link to this post

    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
  2. Maxime
    Maxime avatar
    37 posts
    Member since:
    May 2012

    Posted 25 Jul 2012 Link to this post

    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);
        }
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top