Color Pie Chart by legend Name

2 posts, 1 answers
  1. Vincent
    Vincent avatar
    9 posts
    Member since:
    Sep 2014

    Posted 23 Jun 2015 Link to this post

    I want to color a PieChart I made with unique color depending on the legend.

     pieChart.Series[0].Children[0].BackColor = Color.Red;

    - How can I not change the backcolor of the legend?

    - How can I access the legend name with Series[0].Children[0].


  2. Answer
    Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4166 posts

    Posted 24 Jun 2015 Link to this post

    Hello Vincent,

    Thank you for writing.

    You can customize the chart labels by using the LabelFormatting event. Thus, you can set the ChartViewLabelFormattingEventArgs.LabelElement.BackColor property to Color.Transparent. Additionally, you can customize the label's text as well.
    public Form1()
        this.radChartView1.AreaType = ChartAreaType.Pie;
        PieSeries series = new PieSeries();
        series.DataPoints.Add(new PieDataPoint(50, "Germany"));
        series.DataPoints.Add(new PieDataPoint(70, "United States"));
        series.DataPoints.Add(new PieDataPoint(40, "France"));
        series.DataPoints.Add(new PieDataPoint(25, "United Kingdom"));
        series.ShowLabels = true;
        series.Children[0].BackColor = Color.Red;
        this.radChartView1.LabelFormatting += radChartView1_LabelFormatting;
    private void radChartView1_LabelFormatting(object sender, ChartViewLabelFormattingEventArgs e)
        e.LabelElement.BackColor = Color.Transparent;
        PiePointElement element = (PiePointElement)e.LabelElement.Parent;
        PieDataPoint dataPoint = (PieDataPoint)element.DataPoint;
        e.LabelElement.Text = string.Format("{0:P}, {1}", dataPoint.Label, dataPoint.LegendTitle);

    I hope this information helps. Should you have further questions, I would be glad to help.
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top