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

Pie Chart - Dynamic Slice Styles Issue

2 Answers 106 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 08 Mar 2012, 10:35 PM
I have a pie chart which can display up to 20 slices.  I have to manually set the color for each slice using a converter.

My biggest issue is that the "object value" being passed into the converter isn't the slice datapoint but is the datacontext of the entire chart. Hence, the hard-coded converter parameter (0, 1, ...) so that I know which dataPoint slice is being converted.

So my xaml looks like this (one style per slice (20) which is BAD for maintaining):
<chartView:PieSeries.SliceStyles>
     
    <Style TargetType="Path">
        <Setter Property="Stroke" Value="Gray"/>
        <Setter Property="StrokeThickness" Value="1"/>
        <Setter Property="Fill" Value="{Binding Converter={StaticResource pieChartSliceToColorConverter}, ConverterParameter=0}"/>
         
    </Style>
 
    <Style TargetType="Path">
        <Setter Property="Stroke" Value="Gray"/>
        <Setter Property="StrokeThickness" Value="1"/>
        <Setter Property="Fill" Value="{Binding Converter={StaticResource pieChartSliceToColorConverter}, ConverterParameter=1}"/>
    </Style>

Is there a different style which would eliminate the number of styles I have to maintain?  OR a different approach?

Thanks in advance.

Tracy

2 Answers, 1 is accepted

Sort by
0
Sia
Telerik team
answered on 13 Mar 2012, 04:24 PM
Hi Tracy,

What I can suggest is to try using StyleSelector as follows:
<telerik:RadPieChart>
   <telerik:PieSeries SliceStyleSelector="{StaticResource selector}">
        <telerik:PieSeries.DataPoints>
               <telerik:PieDataPoint Value="20" />
         </telerik:PieSeries.DataPoints>
   </telerik:PieSeries>
</telerik:RadPieChart>

where the static resource is:
<local:MySliceSelector x:Key="selector" />

and the selector is:
public class MySliceSelector : StyleSelector
{
   public override System.Windows.Style SelectStyle(object item, DependencyObject container)
    {
        return base.SelectStyle(item, container);
    }
}

Greetings,
Sia
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Tracy
Top achievements
Rank 1
answered on 15 Mar 2012, 06:23 PM
Thanks for getting back to me.

Using the style selector works really well.

Tracy
Tags
ChartView
Asked by
Tracy
Top achievements
Rank 1
Answers by
Sia
Telerik team
Tracy
Top achievements
Rank 1
Share this question
or