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

Binding color for PieSeries items

2 Answers 118 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
m0rg0t
Top achievements
Rank 1
m0rg0t asked on 11 Mar 2013, 06:32 PM
Hello.

Is it possible to bind color from object property for PieSeries items (when using binding to to custom objects)?


<chart:RadPieChart Width="350" Height="350" Name="AchievesChart">                                                   
    <chart:PieSeries x:Name="AchievesChartPieces"          
         ItemsSource="{Binding Path=Categories}"                      
        DataContext="{Binding Main, Source={StaticResource Locator}}" Loaded="AchievesChartPieces_Loaded">                               
        <chart:PieSeries.LabelDefinitions>
            <chart:ChartSeriesLabelDefinition Binding="ChartLabel"/>
        </chart:PieSeries.LabelDefinitions>
        <!--<chart:PieSeries.SliceStyles>
            <Style TargetType="Path">
                <Setter Property="Fill" Value="Green"/>
                <Setter Property="Stroke" Value="Black" />
            </Style>
        </chart:PieSeries.SliceStyles>-->
    </chart:PieSeries>
</chart:RadPieChart>


2 Answers, 1 is accepted

Sort by
0
m0rg0t
Top achievements
Rank 1
answered on 12 Mar 2013, 11:45 AM
For example if using something like: 

Style testStyle = new Style();
Setter testSetter = new Setter();
testStyle.Setters.Add(testSetter);
(sender as PieSeries).SliceStyles.Add(testStyle);

What testStyle.TargetType should be set to get equal result like:

<chart:PieSeries.SliceStyles>
    <Style TargetType="Path">
        <Setter Property="Fill" Value="Orange"/>
        <Setter Property="Stroke" Value="Black" />
    </Style>
 
    <Style TargetType="Path">
        <Setter Property="Fill" Value="Gray"/>
        <Setter Property="Stroke" Value="Black" />
    </Style>
 
    <Style TargetType="Path">
        <Setter Property="Fill" Value="Cyan"/>
        <Setter Property="Stroke" Value="Black" />
    </Style>
 
    <Style TargetType="Path">
        <Setter Property="Fill" Value="Purple"/>
        <Setter Property="Stroke" Value="Black" />
    </Style>
 
    <Style TargetType="Path">
        <Setter Property="Fill" Value="Green"/>
        <Setter Property="Stroke" Value="Black" />
    </Style>
</chart:PieSeries.SliceStyles>

0
m0rg0t
Top achievements
Rank 1
answered on 12 Mar 2013, 12:34 PM
Find solution

Style testStyle = new Style();
testStyle.TargetType = typeof(System.Windows.Shapes.Path);
Setter testSetter = new Setter();
testSetter.Property = System.Windows.Shapes.Path.FillProperty;                   
testSetter.Value = project.Color.Replace("#","#FF").ToUpper();
testStyle.Setters.Add(testSetter);
 
testSetter = new Setter();
testSetter.Property = System.Windows.Shapes.Path.StrokeProperty;
testSetter.Value = "Black";
testStyle.Setters.Add(testSetter);
 
(sender as PieSeries).SliceStyles.Add(testStyle);
Tags
Chart
Asked by
m0rg0t
Top achievements
Rank 1
Answers by
m0rg0t
Top achievements
Rank 1
Share this question
or