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