Windows Forms Chart series X values always zero

  • Thread starter Thread starter sgrm123
  • Start date Start date
S

sgrm123

Guest
I am working on a simple Windows Forms chart example which produces an XY scatter plot. The code that generates and binds the data for the plot as follows:




void Form1_Load(object sender, EventArgs e)
{
int i;
DataTable dt = new DataTable();
DataRow dr;

dt.Columns.Add(new DataColumn("Xvals"));
dt.Columns.Add(new DataColumn("Yvals"));

for (i = 1; i < 100; ++i)
{
dr = dt.NewRow();
dr["Xvals"] = i*2;
dr["Yvals"] = i * i;
dt.Rows.Add(dr);
}

chart1.Series[0].XValueMember = "Xvals";
chart1.Series[0].YValueMembers = "Yvals";
chart1.DataSource = dt;
chart1.DataBind();

DataPointCollection dpc = chart1.Series[0].Points;

}


This works as expected and the graph displays with the correct X and Y values. However, if I later try look up values in the series (to get the Y value associated with an X position on the chart), I discover that all the DataPoints in the series Points collection have X=0 (the Y values are OK).

This very strange since the data is actually plotted with the correct X axis values. Any ideas as to what is happening here?

Continue reading...
 
Back
Top