WPF工具包饼图未显示

时间:2017-04-01 18:48:38

标签: c# .net wpf xaml charts

我正在尝试使用WPF工具包(System.Windows.Controls.DataVisualization.Toolkit.dll)在WPF中显示饼图

图表本身是由我在XAML中的doind创建的:

<DVC:Chart BorderThickness="0" Title="Arbeitsverteilung" Grid.Column="0" Grid.Row="0" Background="Teal" x:Name="workDist" >
  <DVC:Chart.Series>
    <DVC:PieSeries 
      IndependentValuePath="Key"
      DependentValuePath="Value"
      VerticalAlignment="Top"
      HorizontalAlignment="Stretch"/>
  </DVC:Chart.Series>
</DVC:Chart>

并使用以下方法设置DataSource:

private void LoadData()
{
  ((PieSeries)workDist.Series[0]).ItemsSource =
    new KeyValuePair<string, int>[] {
      new KeyValuePair<string, int> ("Mario", 12),
      new KeyValuePair<string, int> ("Ahner", 14)};
}

这似乎与一个问题很好地协调: 它只显示图表的图例,但不显示图表本身:

screenshot

我已经阅读了一些教程,但每个人都像我一样完成它并且工作正常。

如果有人可以帮助我会很好!

1 个答案:

答案 0 :(得分:2)

取出顶部垂直对齐方式:

    <DVC:Chart BorderThickness="0" Title="Arbeitsverteilung" Grid.Column="0" Grid.Row="0" Background="Teal" x:Name="workDist" >
        <DVC:Chart.Series>
            <DVC:PieSeries 
                IndependentValuePath="Key"
                DependentValuePath="Value"
                HorizontalAlignment="Stretch"
                />
        </DVC:Chart.Series>
    </DVC:Chart>

enter image description here

相关问题