开发者

How to create StackedBarSeries with custom tooltip without losing standard colors

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 Title="SKU Sales" x:Name="chartItemSales" Grid.Column="1">

    <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 Ori开发者_C百科entation="X" ExtendRangeToOrigin="True" Minimum="0" ShowGridLines="True" />
            </chartingToolkit:StackedBarSeries.DependentAxis>

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

</chartingToolkit:Chart>


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"/>

...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜