WPF:图表未绘制图表 [英] WPF: Chart is not plotting the chart

查看:68
本文介绍了WPF:图表未绘制图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发WPF应用程序中的图表.但是它没有显示图表.Chart Plot区域为空白,而我可以在代码中根据valueList.add的数量看到图例的数量.

I am developing a Chart in WPF Application. But it is not showing the chart. Chart Plot area is blank whereas I can see the number of legends on the basis of number of valueList.add I do in the code.

<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.但是在我的图表控件上没有显示任何图表.任何线索,以便我可以完成.

When I run the code I can see the number of legends that too with number 1,2,3 ... so with current code it shows from 1 to 4. but doesn't show any chart on my chart control. Any clue so that I can get it done.

对代码..进行了更改,但结果仍然相同

EDIT : A Change has been made to the code .. but still the same result

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

valueList.Add 的添加时间.我可以在图表上显示相同数量的图例,但没有图表:(

the number of time valueList.Add is added. I can the same number of legends on the chart but no chart :(

希望有人可以帮助我!!!

Hope Somebody can help me !!!

推荐答案

此处是指向图表完整源代码的链接. https://www.dropbox.com/s/helas5e8qdr1xhs/WPF.zip?dl = 0

Here is the link to complete source code for the chart. https://www.dropbox.com/s/helas5e8qdr1xhs/WPF.zip?dl=0

这篇关于WPF:图表未绘制图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆