RadChart Legend/ Marker Color

Thread is closed for posting
5 posts, 0 answers
  1. Ashish
    Ashish avatar
    3 posts
    Member since:
    Oct 2010

    Posted 08 Apr 2011 Link to this post

         Hello Please Help, i want to change colors of legend marker i mean the color of  rectangle, currently they are auto-generated.  
       Below is my code (6-series).

           rcScorecard.Series.Clear();
            rcScorecard.PlotArea.XAxis.Items.Clear();
            rcScorecard.PlotArea.YAxis.Items.Clear();

            rcScorecard.Skin = "Vista";
            rcScorecard.Series.Clear();
            rcScorecard.AutoLayout = true;

            rcScorecard.PlotArea.XAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font = new System.Drawing.Font("Verdana", 12, System.Drawing.FontStyle.Bold);
            rcScorecard.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font = new System.Drawing.Font("Verdana", 12, System.Drawing.FontStyle.Bold);

            //rcScorecard.PlotArea.YAxis.AutoScale = false;
            rcScorecard.PlotArea.YAxis.Step = 1;
            rcScorecard.PlotArea.YAxis.AxisLabel.TextBlock.Appearance.TextProperties.Font = new System.Drawing.Font("Verdana", 12, System.Drawing.FontStyle.Bold);
            rcScorecard.PlotArea.YAxis.AxisLabel.Visible = true;
            rcScorecard.PlotArea.YAxis.AxisLabel.TextBlock.Text = "Percentage (%)";

            rcScorecard.PlotArea.XAxis.AutoScale = false;
            rcScorecard.PlotArea.XAxis.AddItem(reportDate.AddMonths(-2).ToString("MMMM").Substring(0, 3) + reportDate.AddMonths(-2).Year.ToString());
            rcScorecard.PlotArea.XAxis.AddItem(reportDate.AddMonths(-1).ToString("MMMM").Substring(0, 3) + reportDate.AddMonths(-1).Year.ToString());
            rcScorecard.PlotArea.XAxis.AddItem(reportDate.ToString("MMMM").Substring(0, 3) + reportDate.Year.ToString());

            for (int count = 0; count < tblReport.Rows.Count; count++)
            {
                ChartSeries series = new ChartSeries();
                series.Name = tblReport.Rows[count][0].ToString();
                series.Type = ChartSeriesType.Line;
                rcScorecard.Series.Add(series);
                series.Items.Clear();
                for (int columnCount = 2; columnCount <= 4; columnCount++)
                {
                    ChartSeriesItem item = new ChartSeriesItem();
                    item.YValue = Convert.ToDouble(tblReport.Rows[count][columnCount]);
                    series.Items.Add(item);
                }
            }
  2. Sia
    Admin
    Sia avatar
    667 posts

    Posted 13 Apr 2011 Link to this post

    Hello Ashish,

    You can change the legend markers' color on BeforeLayout:

    rcScorecard.BeforeLayout += new EventHandler<EventArgs>(rcScorecard_BeforeLayout);
     
    void rcScorecard_BeforeLayout(object sender, EventArgs e)
    {
        List<Color> l = new List<Color>{Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Olive, Color.Pink};
        int i = 0;
        foreach (var item in rcScorecard.Legend.Items)
        {
            item.Marker.Appearance.FillStyle.FillType = FillType.Solid;
            item.Marker.Appearance.FillStyle.MainColor = l[i];
            item.Marker.Appearance.Border.Color = Color.Transparent;
            i++;
        }
    }

    Greetings,
    Sia
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ashish
    Ashish avatar
    3 posts
    Member since:
    Oct 2010

    Posted 14 Apr 2011 Link to this post

    Thank you very much Sia.
  5. Shaun
    Shaun avatar
    1 posts
    Member since:
    Jan 2011

    Posted 30 Aug 2012 Link to this post

    Sia,
     I'm trying to get the color of a series prior to rendering the page and use it in a data grid below the chart.  I've tried getting the color during series genration, pre render and pre render complete but the color is always 0,0,0,0 for all series.  I'm using the Office 2007 skin, so I'm assuming at this point the skin is providing the colors last second and there may not be a good way to get the colors of each series.  Below is my loop code to get my colors I've been trying.  Any thoughts?

    foreach

     

     

    (

    ChartSeries s in RadChart1.Series)

    {

     

     

    //s.Appearance.LineSeriesAppearance.Color=CreateRandomColor();

     

     

    Color seriesColor = s.Appearance.LineSeriesAppearance.Color;

    updateLenderGridColorBySeries(s.Name, seriesColor);

    }

  6. Sia
    Admin
    Sia avatar
    667 posts

    Posted 04 Sep 2012 Link to this post

    Hello Ashish,

    Please try to get the colors on the BeforeLayout or PrePaint event as follows:

    void RadChart1_BeforeLayout(object sender, EventArgs e)
    {
         Color seriesColor = RadChart1.Series[0].Appearance.LineSeriesAppearance.Color;
    }

    Regards,
    Sia
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017