silverlight 4显示多个饼图

发布于 2024-11-18 00:34:37 字数 2876 浏览 2 评论 0 原文

代码:

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

没有边距,三个饼叠加为一个。我怎样才能把它们分成三部分?注意:使用 一切都按预期工作。

我想更好的问题是:如何用一个图例显示三个馅饼?

编辑:解决方案 就像 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"

所有图表共享相同的数据上下文。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-11-25 00:34:37

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文