How to bind a dictionary to MSChart

邮差的信 提交于 2020-05-26 05:59:46

问题


I am trying to bind Dictionary to a Chart, Below is the code

    IDictionary<double, double> dict1 = new Dictionary<double, double>();
    IList<double> list1 = new List<double>();
    public Form1()
    {
        InitializeComponent();
        InitialiseDictionary();

        Series ser1 = new Series("My Series", 10);
        chart1.Series.Add(ser1);
        chart1.DataSource = dict1;
        chart1.DataBind();
    }

    private void InitialiseDictionary()
    {
        for (int i = 0, j = 1; i < 1000;i = i + 100 , j=j+10)
            dict1.Add(i , j);
    }

But I don't see the Chart or graph on winform. am I missing anything?


回答1:


I got the solution, the constructor Form1() is modified as below

public Form1()
{
    InitializeComponent();
    InitialiseDictionary();
    Series ser1 = new Series("My Series", 10);
    chart1.Series.Add(ser1);
    chart1.Series["My Series"].Points.DataBindXY(dict1.Keys, dict1.Values);
}


来源:https://stackoverflow.com/questions/8121804/how-to-bind-a-dictionary-to-mschart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!