开发者

silverlight 4 display multiple pie charts

Code:

<toolkit:Chart x:Name="pieChart" Grid.Row="2" Title="">

    <toolkit:Chart.Series>
        <toolkit:PieSeries ItemsSource="{Binding}"
                           IndependentValueBinding="{Binding A}"
                           DependentValueBinding="{Binding X}"
                           Margin="-500,0,0,0">                    
        </toolkit:PieSeries>
        <toolkit:PieSeries ItemsSource="{Binding}"
     开发者_JAVA技巧                      IndependentValueBinding="{Binding A}"
                           DependentValueBinding="{Binding Y}"
                           Margin="0,0,0,0"/>
        <toolkit:PieSeries ItemsSource="{Binding}"
                           IndependentValueBinding="{Binding A}"
                           DependentValueBinding="{Binding Z}"
                           Margin="500,0,0,0"/>

    </toolkit:Chart.Series>
</toolkit:Chart>

Without margins three pies overlay to one. How do I make them split into three? Note: with <toolkit:ColumnSeries everything works as expected.

I guess a better question would be: how do I show three pies with one legend?

EDIT: Solution Like vorrtex suggested, I found no simpler way of doing this. A chart without a legend:

           <toolkit:Chart x:Name="pieChart" LegendStyle="{StaticResource NoLegendStyle}">
            <toolkit:Chart.Series>
                <toolkit:PieSeries ItemsSource="{Binding}"
                                   IndependentValueBinding="{Binding A}"
                                   DependentValueBinding="{Binding X}"/>                    
            </toolkit:Chart.Series>
        </toolkit:Chart>

A Legend without a chart:

<toolkit:Chart x:Name="pieChart3"   ChartAreaStyle="{StaticResource NoChartStyle}">
                    <toolkit:Chart.Series>
                        <toolkit:PieSeries ItemsSource="{Binding}"
                                       IndependentValueBinding="{Binding A}"
                                       DependentValueBinding="{Binding X}"/>
                    </toolkit:Chart.Series>
                </toolkit:Chart>

Where styles are:

<UserControl.Resources>
    <Style x:Key ="NoLegendStyle" TargetType="toolkit:Legend">
        <Setter Property="Height" Value="0" />
        <Setter Property="Width" Value="0" />
    </Style>
    <Style x:Key ="NoChartStyle" TargetType="chartingPrimitivesToolkit:EdgePanel">
        <Setter Property="Height" Value="0" />
        <Setter Property="Width" Value="0" />
    </Style>
</UserControl.Resources>

and

xmlns:chartingPrimitivesToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting.Primitives;assembly=System.Windows.Controls.DataVisualization.Toolkit"

All charts share same datacontext.


Disable the legend on 2 of the charts. Then programmatically add the legend items to the legend you are displaying.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜