我正在尝试使用 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)};
}
这似乎可以很好地解决一个问题: 它只显示图表的图例,而不显示图表本身:
我已经阅读了一些教程,但每个人都按照我的做法进行操作,而且效果很好。
如果有人能帮助我就好了!
最佳答案
取出顶部垂直对齐:
<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>
关于c# - WPF 工具包饼图不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43160702/