Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Windows Phone 7 > Chart > Multiple pie chart labels

Not answered Multiple pie chart labels

Feed from this thread
  • Christopher avatar

    Posted on Jul 5, 2012 (permalink)

    Hi,

    I'm trying to display multiple labels simultaneously next to each other on a pie chart. I found an old thread that made reference to this workaround. However, I'm having trouble implementing this strategy, because it seems the DataPoint is always {0, 0, 0, 0}. How can this be done? Thanks!

    Reply

  • Victor Victor admin's avatar

    Posted on Jul 9, 2012 (permalink)

    Hi Chris,

    Thanks for writing.
    Please explain in more detail about your scenario. By "the DataPoint is always {0,0,0,0}" do you mean that the point's LayoutSlot is {0,0,0,0}? The thread your linked to seems to contain a working example. Can you please send a sample application that demonstrates you scenario. This way I can debug/tweak it and help you further.
    I am looking forward to your reply.

    Greetings,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

  • Christopher avatar

    Posted on Jul 9, 2012 (permalink)

    Hi Victor,

    This appears to be a bug in RadPieChart, as I've used this same approach with success in a RadCartesianChart. The RadPieChart I'm using is defined as follows:

    <telerik:RadPieChart>
        <telerikChart:PieSeries ValueBinding="Value">
            <telerikChart:PieSeries.LabelDefinitions>
                <telerikChart:ChartSeriesLabelDefinition>
                    <telerikChart:ChartSeriesLabelDefinition.Strategy>
                        <core:PieChartLabelStrategy />
                    </telerikChart:ChartSeriesLabelDefinition.Strategy>
                </telerikChart:ChartSeriesLabelDefinition>
            </telerikChart:PieSeries.LabelDefinitions>
        </telerikChart:PieSeries>
    </telerikChart:RadPieChart>

    And PieChartLabelStrategy can be anything as simple as:

    public class PieChartLabelStrategy : ChartSeriesLabelStrategy
    {
        public override LabelStrategyOptions Options
        {
            get
            {
                return LabelStrategyOptions.Arrange;
            }
        }
      
        public override RadRect GetLabelLayoutSlot(DataPoint point, FrameworkElement visual, int labelIndex)
        {
            return base.GetLabelLayoutSlot(point, visual, labelIndex);
        }
    }

    Putting a breakpoint on the call to the base method shows that point.LayoutSlot is always {0,0,0,0}.

    Any help you can provide is appreciated! Thanks!

    Reply

  • Victor Victor admin's avatar

    Posted on Jul 12, 2012 (permalink)

    Hi Christopher,

    Thank you for writing again.
    Please have a look at this implementation of the layout strategy. You can use it as a basis for further tweaking.

    public partial class MainPage : PhoneApplicationPage
        {
            public MainPage()
            {
                InitializeComponent();
                this.chart.Series[0].ItemsSource = new int[] { 1,1,1,1 };
     
                PieChartLabelStrategy strategy = new PieChartLabelStrategy(this.chart);
                ChartSeriesLabelDefinition definition = new ChartSeriesLabelDefinition();
                definition.Strategy = strategy;
     
                this.chart.Series[0].LabelDefinitions.Add(definition);
            }
        }
     
        public class PieChartLabelStrategy : ChartSeriesLabelStrategy
        {
            RadPieChart chart;
            public PieChartLabelStrategy(RadPieChart chart)
            {
                this.chart = chart;
            }
     
            public override LabelStrategyOptions Options
            {
                get
                {
                    return LabelStrategyOptions.Arrange;
                }
            }
     
            public override RadRect GetLabelLayoutSlot(DataPoint point, FrameworkElement visual, int labelIndex)
            {
                PieDataPoint piePoint = (PieDataPoint)point;
     
                IChartView view = this.chart as IChartView;
                Point center = new Point(view.ViewportWidth / 2, view.ViewportHeight / 2);
                double radius = (Math.Min(view.ViewportWidth , view.ViewportHeight) / 2) * 0.5;
                visual.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                Size pointSize = new Size(visual.ActualWidth, visual.ActualHeight);
     
                RadRect result = RadRect.Empty;
                double angle = Math.Round(piePoint.StartAngle + piePoint.SweepAngle / 2) * 0.0174532925;
                result.X = (center.X + radius * Math.Cos(angle)) - pointSize.Width / 2;
                result.Y = (center.Y + radius * Math.Sin(angle)) - pointSize.Height / 2;
                result.Width = pointSize.Width;
                result.Height = pointSize.Height;
     
                return result;
            }
        }

    <telerikChart:RadPieChart x:Name="chart"
                              Palette="Warm">
        <telerikChart:PieSeries ValueBinding="Value"/>
    </telerikChart:RadPieChart>

    Please write again if you need further assistance.

    Regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Windows Phone 7 > Chart > Multiple pie chart labels