This question is locked. New answers and comments are not allowed.
Christopher
Top achievements
Rank 1
Christopher
asked on 05 Jul 2012, 06:14 PM
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!
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!
3 Answers, 1 is accepted
0
Hi Chris,
Victor
the Telerik team
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.
Victor
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Christopher
Top achievements
Rank 1
answered on 09 Jul 2012, 05:00 PM
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:
And PieChartLabelStrategy can be anything as simple as:
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!
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!
0
Hi Christopher,
Please write again if you need further assistance. Regards,
Victor
the Telerik team
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 >>