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

Custom legend textcolor disappearing after selection

2 Answers 35 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yunuen Sanchez
Top achievements
Rank 1
Yunuen Sanchez asked on 18 Mar 2015, 07:43 AM
I customized the legend labels on a Pie Chart using the following code:

for (nuint i = 0; i < chart.Legend.Container.ItemCount; i++) {
     TKChartLegendItem item = chart.Legend.Container.ItemAtIndex (i);
     item.Label.TextColor = UIColor.White;
     item.BackgroundColor = UIColor.Black;
}

Everything looks fine until I select one of the points. The TextColor of the label goes back to its original Black color. BackgroundColor remains black, only TextColor changed.

What I am missing?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 18 Mar 2015, 02:25 PM
Hi Yunuen,

You should implement TKChartDelegate and override its UpdateLegendItem method in this scenario. It will be called every time when a legend item needs to be updated. Consider the following sample:
class ChartDelegate: TKChartDelegate
{
    public override void UpdateLegendItem (TKChart chart, TKChartLegendItem item, TKChartSeries series, nuint index)
    {
        item.Label.TextColor = UIColor.Red;
    }
}

Set the chart delegate before adding the chart to the superview and before setting the Hidden property of chart legend to false:
chart.Delegate = new ChartDelegate ();
this.View.AddSubview (chart);

Do not hesitate to contact us if you have further questions.

Regards,
Jack
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Yunuen Sanchez
Top achievements
Rank 1
answered on 18 Mar 2015, 03:20 PM
It works! Thanks Jack. 
Tags
Chart
Asked by
Yunuen Sanchez
Top achievements
Rank 1
Answers by
Jack
Telerik team
Yunuen Sanchez
Top achievements
Rank 1
Share this question
or