Custom legend textcolor disappearing after selection

3 posts, 1 answers
  1. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 18 Mar 2015 Link to this post

    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. Answer
    Jack
    Admin
    Jack avatar
    2335 posts

    Posted 18 Mar 2015 Link to this post

    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.

     
  3. DevCraft banner
  4. Yunuen Sanchez
    Yunuen Sanchez avatar
    31 posts
    Member since:
    Aug 2009

    Posted 18 Mar 2015 in reply to Jack Link to this post

    It works! Thanks Jack. 
Back to Top