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

Color Pie Chart by legend Name

1 Answer 345 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 23 Jun 2015, 01:58 PM

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].

Thanks

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jun 2015, 10:38 AM
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()
{
    InitializeComponent();
    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;
    this.radChartView1.Series.Add(series);
 
    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.
 
Regards,
Dess
Telerik
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
Tags
ChartView
Asked by
Vincent
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or