1

I am able to change the colour of a silverlight Pie chart or change the tooltip design. What i want is to do both.

This is the code i have for my chart:

                <charts:Chart x:Name="MyChart" Title="MyChart">
                    <charts:Chart.LegendStyle>
                        <Style TargetType="datavis:Legend">
                            <Setter Property="Width" Value="0"/>
                        </Style>
                    </charts:Chart.LegendStyle>
                    <charts:PieSeries 
                    ItemsSource="{Binding}"
                    IndependentValuePath="Title"
                    DependentValuePath="Value"  
                    SelectionChanged="PieSeries_SelectionChanged" 
                    DataPointStyle="{StaticResource MyPieDataPointTemplate}">
                    </charts:PieSeries>
                </charts:Chart>

And here is the resource for myPieDataPointTemplate:

<Style x:Key="MyPieDataPointTemplate" TargetType="toolkit:PieDataPoint">
    <Setter Property="BorderBrush" Value="Black"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="toolkit:PieDataPoint">
                <Grid x:Name="Root" Opacity="0">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Normal"/>
                            <VisualState x:Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" 
                                     Storyboard.TargetName="MouseOverHighlight" 
                                     Storyboard.TargetProperty="Opacity" To="0.6"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="SelectionStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.1"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Unselected"/>
                            <VisualState x:Name="Selected">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" 
                                     Storyboard.TargetName="SelectionHighlight" 
                                     Storyboard.TargetProperty="Opacity" To="0.6"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup x:Name="RevealStates">
                            <VisualStateGroup.Transitions>
                                <VisualTransition GeneratedDuration="0:0:0.5"/>
                            </VisualStateGroup.Transitions>
                            <VisualState x:Name="Shown">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" 
                                     Storyboard.TargetName="Root" 
                                     Storyboard.TargetProperty="Opacity" 
                                     To="1"/>
                                    <DoubleAnimation 
                        Storyboard.TargetName="Slice" 
                        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                        To="1" />
                                    <DoubleAnimation 
                        Storyboard.TargetName="Slice" 
                        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                        To="1" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Hidden">
                                <Storyboard>
                                    <DoubleAnimation Duration="0" 
                                     Storyboard.TargetName="Root" 
                                     Storyboard.TargetProperty="Opacity" 
                                     To="0"/>
                                    <DoubleAnimation 
                        Storyboard.TargetName="Slice" 
                        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"
                        To="0" />
                                    <DoubleAnimation 
                        Storyboard.TargetName="Slice" 
                        Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"
                        To="0" />
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Path x:Name="Slice" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" Data="{TemplateBinding Geometry}" RenderTransformOrigin="0.5,0.5">
                        <Path.RenderTransform>
                            <TransformGroup>
                                <ScaleTransform ScaleX="0" ScaleY="0"/>
                                <SkewTransform/>
                                <RotateTransform/>
                                <TranslateTransform/>
                            </TransformGroup>
                        </Path.RenderTransform>
                        <ToolTipService.ToolTip>
                            <StackPanel>
                                <ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
                                <ContentControl Content="{TemplateBinding FormattedRatio}"/>
                            </StackPanel>
                        </ToolTipService.ToolTip>
                    </Path>
                    <Path x:Name="SelectionHighlight" IsHitTestVisible="False" Opacity="0" Fill="Red" Data="{TemplateBinding GeometrySelection}"/>
                    <Path x:Name="MouseOverHighlight" IsHitTestVisible="False" Opacity="0" Fill="White" Data="{TemplateBinding GeometryHighlight}"/>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
vortexwolf
  • 13,967
  • 2
  • 54
  • 72
Bruie
  • 1,195
  • 3
  • 11
  • 18
  • What number of colors do you want to change? If more than one (and it seems to be so, because it is not cool to have one-color charts) add these colors to the question. Also I have answered the similar question for Column series. It might be interesting to you: http://stackoverflow.com/questions/5618581/silverlight-4-chart-toolkit-color-set/5626435#5626435 – vortexwolf Apr 21 '11 at 18:15
  • This question is not about jut changing the colours it is about changing the colours and having a custom tool tip at the same time. I dont mind what colours i use. – Bruie Apr 26 '11 at 09:16
  • 1
    Add to the MyPieDataPointTemplate the code ``. After that you can change the code inside the `ToolTipService.ToolTip`. And everything will be inside one style. – vortexwolf Apr 26 '11 at 21:53

0 Answers0