views:

448

answers:

1

I have a StackedBarSeries in Silverlight 4 charting (latest release).

I have created a DataPointStyle called MyDataPointStyle for a custom tooltip. By itself this breaks the standard palette used for the different bars.

I've applied a custom palette - as described in David Anson's blog to the chart. However when I have the DataPointStyle set for my SeriesDefinition objects it does not use this palette.

I'm not sure what I'm missing - but David specifically says :

... it enables the use of DynamicResource (currently only supported by the WPF platform) to let users customize their DataPointStyle without inadvertently losing the default/custom Palette colors. (Note: A very popular request!)

Unfortunately I'm inadvertently losing these colors - and I can't see why?

    <chartingToolkit:Chart.Palette>
        <dataviz:ResourceDictionaryCollection>
            <ResourceDictionary>
                <Style x:Key="DataPointStyle" TargetType="Control">
                    <Setter Property="Background" Value="Blue"/>
                </Style>
            </ResourceDictionary>
            <ResourceDictionary>
                <Style x:Key="DataPointStyle" TargetType="Control">
                    <Setter Property="Background" Value="Green"/>
                </Style>
            </ResourceDictionary>
            <ResourceDictionary>
                <Style x:Key="DataPointStyle" TargetType="Control">
                    <Setter Property="Background" Value="Red"/>
                </Style>
            </ResourceDictionary>
        </dataviz:ResourceDictionaryCollection>
    </chartingToolkit:Chart.Palette>

    <chartingToolkit:Chart.Series>

        <chartingToolkit:StackedBarSeries>

            <chartingToolkit:SeriesDefinition
                        IndependentValueBinding="{Binding SKU}" 
                        DependentValueBinding="{Binding Qty}" 
                        DataPointStyle="{StaticResource MyDataPointStyle}"
                        Title="Regular"/>

            <chartingToolkit:SeriesDefinition
                        IndependentValueBinding="{Binding SKU}" 
                        DependentValueBinding="{Binding Qty}" 
                        DataPointStyle="{StaticResource MyDataPointStyle}"
                        Title="FSP Orders"/>

            <chartingToolkit:StackedBarSeries.IndependentAxis>
                <chartingToolkit:CategoryAxis Title="SKU" Orientation="Y" FontStyle="Italic" AxisLabelStyle="{StaticResource LeftAxisStyle}"/>
            </chartingToolkit:StackedBarSeries.IndependentAxis>

                <chartingToolkit:StackedBarSeries.DependentAxis>
                <chartingToolkit:LinearAxis Orientation="X" ExtendRangeToOrigin="True" Minimum="0" ShowGridLines="True" />
            </chartingToolkit:StackedBarSeries.DependentAxis>

        </chartingToolkit:StackedBarSeries >
    </chartingToolkit:Chart.Series>

</chartingToolkit:Chart>
+2  A: 

The clue is in the quote you posted from David "currently only supported by the WPF platform" that is, its not supported on Silverlight.

As soon as you supply your own DataPointStyle you replace any style that would have been supplied by the Palette (either the default one or your custom palette).

Edit:

Here is how its done. Instead of supplying a style to the DataPointStyle property of a series or definition you leave it to the pallete. However the Styles in the palette can use the Style object's BasedOn property to avoid duplication. So:-

<UserControl.Resources>
   <Style x:Key="MyDataPointStyle" TargetType="DataPoint">
     <!-- Set up the general style for the points may even include a Template -->
   </Style>

...

<chartingToolkit:Chart.Palette>      
    <dataviz:ResourceDictionaryCollection>      
        <ResourceDictionary>      
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:BarDataPoint" BasedOn="{StaticResource MyDataPointStyle}" >      
                <Setter Property="Background" Value="Blue"/>      
            </Style>      
        </ResourceDictionary>      
        <ResourceDictionary>      
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:BarDataPoint" BasedOn="{StaticResource MyDataPointStyle}">      
                <Setter Property="Background" Value="Green"/>      
            </Style>      
        </ResourceDictionary>      
        <ResourceDictionary>      
            <Style x:Key="DataPointStyle" TargetType="chartingToolkit:BarDataPoint" BasedOn="{StaticResource MyDataPointStyle}">      
                <Setter Property="Background" Value="Red"/>      
            </Style>
        </ResourceDictionary>          
    </dataviz:ResourceDictionaryCollection>          
</chartingToolkit:Chart.Palette>          

<chartingToolkit:Chart.Series>          

    <chartingToolkit:StackedBarSeries>          

        <chartingToolkit:SeriesDefinition          
                    IndependentValueBinding="{Binding SKU}"           
                    DependentValueBinding="{Binding Qty}"           
                    Title="Regular"/>

...

AnthonyWJones
i'd read that as 'up until now' (all three times I read that sentence). hmm i guess that would explain it. i'm still confused how i can apply the custom palette into the style? the 'Palette' structure above is set on the 'Palette' property of Chart but there is no 'Palette' member on a BarDataPoint.
Simon_Weaver
@Simon: A palette provides a set of __styles__. The DataPoints for each series is allocated a style from the "palette". Hence the missing `Palette` property you are looking for is actually the `Style` property. If you supply your own value for the DataPointStyle then that supercedes any supplied by the palette.
AnthonyWJones
@anthonywjones so if i want 3 different colors in my chart do i have to supply a palette with the datapointstyle duplicated in its entirity 3 times - each with a different color?
Simon_Weaver
@Simon: Edited this answer to give an example, the solution is to use the `BasedOn` property of each `Style` in the pallete to point at your `MyDataPointStyle` then remove the `DataPointStyle` from the series definitions.
AnthonyWJones
@anthonywjones - thanks so much! getting better understanding how all these Xaml pieces fit together - but sometimes the solution is just too wierd to figure out without knowing more about the internals. got it working now! (made couple minor tweaks to your sample)
Simon_Weaver