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

Legend Chart Pie

1 Answer 192 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Flavio
Top achievements
Rank 1
Flavio asked on 26 Jun 2014, 12:00 AM
Hi! 
 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.Series.Clear();
           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.DataPoints.Add(_point);
           }
           //_pie.ShowLabels = true;
           _pie.LabelMode = PieLabelModes.Horizontal;        
           this.grfPieReceitaAlunoPorPlano.Series.Add(_pie);
       }

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 26 Jun 2014, 01:07 PM
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)
    {
        base.OnAttached(parent);
 
        FieldInfo fieldInfo = typeof(PiePointElement).GetField("legendItem", BindingFlags.Instance | BindingFlags.NonPublic);
        LegendItem legendItem = fieldInfo.GetValue(this) as LegendItem;
 
        if (legendItem == null)
        {
            return;
        }
 
        LegendItemCollection legendItems = ((ILegendInfoProvider)this.View.Area).LegendInfos;
 
        while (legendItems.Contains(legendItem))
        {
            legendItems.Remove(legendItem);
        }
 
        legendItems.Add(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.

Regards,
Ivan Petrov
Telerik
 
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.
 
Tags
ChartView
Asked by
Flavio
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or