Legend Chart Pie

2 posts, 0 answers
  1. Flavio
    Flavio avatar
    22 posts
    Member since:
    Jan 2011

    Posted 25 Jun 2014 Link to this post

     I'm creating a dashboard with some charts, when I requested to pie chart show your values, the category legend appears duplicated. I'd like know why occurs it?

    listaObj = 6 records.

    private void GraficoReceitaPorPlano(IList<object> listaObj)
               this.grfPieReceitaAlunoPorPlano.AreaType = ChartAreaType.Pie;
               this.grfPieReceitaAlunoPorPlano.ShowTitle = true;
               this.grfPieReceitaAlunoPorPlano.Title = "Receita de Alunos Por Plano";
               this.grfPieReceitaAlunoPorPlano.ChartElement.TitlePosition = TitlePosition.Top;
               this.grfPieReceitaAlunoPorPlano.ChartElement.TitleElement.TextAlignment = ContentAlignment.MiddleCenter;
               this.grfPieReceitaAlunoPorPlano.ShowLegend = true;           
               this.grfPieReceitaAlunoPorPlano.ChartElement.LegendElement.TitleElement.Text = "Plano";
               this.grfPieReceitaAlunoPorPlano.ChartElement.LegendElement.TitleElement.TextAlignment = ContentAlignment.MiddleCenter;
               this.grfPieReceitaAlunoPorPlano.ShowToolTip = true;      
               PieSeries _pie = new PieSeries();
               foreach (object[] _obj in listaObj)
                   double _valor = (double)ValidarCampoNumerico.TryDecimal(_obj[4].ToString());
                   PieDataPoint _point = new PieDataPoint(_valor, _obj[2].ToString());
                   _point.Label = _obj[2];               
               //_pie.ShowLabels = true;
               _pie.LabelMode = PieLabelModes.Horizontal;        
  2. Ivan Petrov
    Ivan Petrov avatar
    701 posts

    Posted 26 Jun 2014 Link to this post

    Hello Flavio,

    Thank you for writing.

    I was able to reproduce the issue you have described and have logged it in our Feedback Portal under the following link - Feedback item. By following the link you will be able to subscribe for status changes, comment and vote for the item.

    Until the issue is addressed you can use one of two workarounds:
    1. Call your chart population logic from the form OnLoad event instead of the constructor.
    2. Creating a custom PiePointElement. This is practically the segments that are drawn in the pie chart. Here is how to create a custom PiePointElement:
    public class MyPiePointElement : PiePointElement
        public MyPiePointElement(PieDataPoint dataPoint)
            : base(dataPoint)
        { }
        protected override void OnAttached(UIChartElement parent)
            FieldInfo fieldInfo = typeof(PiePointElement).GetField("legendItem", BindingFlags.Instance | BindingFlags.NonPublic);
            LegendItem legendItem = fieldInfo.GetValue(this) as LegendItem;
            if (legendItem == null)
            LegendItemCollection legendItems = ((ILegendInfoProvider)this.View.Area).LegendInfos;
            while (legendItems.Contains(legendItem))

    To use this custom elements you have to subscribe to the CreatePointElement event of RadChartView and put the following code in the event handler:
    private void radChartView1_CreatePointElement(object sender, ChartViewCreatePointElementEventArgs e)
        if (e.DataPoint is PieDataPoint)
            e.DataPointElement = new MyPiePointElement(e.DataPoint as PieDataPoint);

    I have updated your Telerik Points for bringing this issue to our attention.

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Ivan Petrov
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
  3. DevCraft banner
Back to Top