c# - WPF 工具包饼图不显示

标签 c# .net wpf xaml charts

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

图表本身是通过在我的 XAML 中这样做创建的:

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

我使用以下方法设置数据源:

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

我已经阅读了一些教程,但每个人都按照我的做法进行操作,而且效果很好。

如果有人能帮助我就好了!

最佳答案

取出顶部垂直对齐:

    <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

关于c# - WPF 工具包饼图不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43160702/

相关文章:

.net - 将 CLR 主机注入(inject)正在运行的进程 - 可能吗?

c# - %在C#中是什么意思?

c# - 列表框 SelectedItem 绑定(bind)到 UserControl

c++ - Windows 通用应用程序 (XAML) : textBlock->Text cannot be called with the given argument list

c# - 以数字为键反序列化 JSON

c# - 如何清理异常字符串以便可以通过 Javascript Alert 显示?

c# - 使用 C# 在 Powerpoint 2013 中创建具有多个系列的图表

wpf - 客户服务架构

javascript - 从不同的文件夹访问母版页

c# - ASP.NET - 如何检查一个或多个字段值是否已更改