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

RadChart Legend/ Marker Color

4 Answers 206 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ashish
Top achievements
Rank 1
Ashish asked on 08 Apr 2011, 08:25 AM
     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);
            }
        }

4 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 13 Apr 2011, 04:24 PM
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.

0
Ashish
Top achievements
Rank 1
answered on 14 Apr 2011, 07:06 AM
Thank you very much Sia.
0
Shaun
Top achievements
Rank 1
answered on 30 Aug 2012, 07:22 PM
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);

}

0
Sia
Telerik team
answered on 04 Sep 2012, 02:02 PM
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.
Tags
Chart (Obsolete)
Asked by
Ashish
Top achievements
Rank 1
Answers by
Sia
Telerik team
Ashish
Top achievements
Rank 1
Shaun
Top achievements
Rank 1
Share this question
or