silverlight 4显示多个饼图

时间:2011-06-30 11:54:36

标签: silverlight silverlight-4.0 charts silverlight-toolkit pie-chart

代码:

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

没有边距,三个馅饼重叠到一个。如何将它们分成三部分?注意:使用<toolkit:ColumnSeries一切都按预期工作。

我想一个更好的问题是:如何用一个传奇展示三个馅饼?

编辑:解决方案 像vorrtex建议的那样,我发现没有更简单的方法。没有图例的图表:

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

没有图表的传奇:

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

样式在哪里:

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

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

所有图表共享相同的datacontext。

1 个答案:

答案 0 :(得分:0)

禁用其中两个图表上的图例。然后以编程方式将图例项添加到您正在显示的图例中。