WPF:Chart未绘制图表
本文关键字:绘制 Chart WPF | 更新日期: 2023-09-27 18:20:32
我正在WPF应用程序中开发一个图表。但它并没有显示图表。图表绘图区域是空白的,而我可以根据代码中的值List的数量看到图例的数量。
XAML
<chartingToolkit:Chart HorizontalAlignment="Stretch"
x:Name="MyPie"
Margin="10"
Title="Total Voting Percentage"
VerticalAlignment="Stretch">
<chartingToolkit:PieSeries ItemsSource="{Binding}"
DependentValuePath="Total Participants"
IndependentValuePath="Total Voted" />
</chartingToolkit:Chart>
代码隐藏
public partial class TotalVoting : Window
{
int TotalParticipant;
int TotalVoted;
public TotalVoting()
{
InitializeComponent();
TotalParticipant = int.Parse(da[0].ToString()); //data reaches here
TotalVoted = int.Parse(da1[0].ToString()) / 2; //data reaches here
ObservableCollection<Writer> Team = new ObservableCollection<Writer>
{
new Writer("Total Participants", TotalParticipant),
new Writer("Participants Voted", TotalVoted),
new Writer("Total Participants", TotalParticipant),
new Writer("Participants Voted", TotalVoted)
};
MyPie.DataContext = Team;
}
}
public class Writer
{
public Writer() { }
public Writer(string writerName, int numOfTypes)
{
Name = writerName;
Types = numOfTypes;
}
public string Name { get; set; }
public int Types { get; set; }
}
当我运行代码时,我可以看到图例的数量,数字为1,2,3。。。因此,对于当前代码,它显示从1到4。但在我的图表控件上没有显示任何图表。任何能让我完成的线索。
编辑:代码已更改。。但的结果仍然相同
public void GenerateChart()
{
List<KeyValuePair<string, double>> valueList = new List<KeyValuePair<string, double>>();
valueList.Add(new KeyValuePair<string, double>("Apple", 101));
valueList.Add(new KeyValuePair<string, double>("Banana", 201));
valueList.Add(new KeyValuePair<string, double>("Cake", 20));
valueList.Add(new KeyValuePair<string, double>("Others", 200));
pieChart.Title = "Top Products";
pieChart.DataContext = valueList;
}
加上时间数CCD_ 1。我可以在图表上显示相同数量的图例,但没有图表:(
希望有人能帮我!!!
这里是完成图表源代码的链接。https://www.dropbox.com/s/helas5e8qdr1xhs/WPF.zip?dl=0