我做了一个曲线图,数据来源于数据库,
这张表中有两个series(也有两条线),数据来源于不同的两张表(node_002_temperature与node_003_temperature),但X轴均为时间
当其中一个series已经存在于chart中时,再添加另一个series时会提示;
“如果索引序列(XValueIndexed = true)不对齐,则无法在同一个轴上显示它们。序列“node_002_temperature”和序列“node_003_temperature”必须对齐才能执行此操作。当前这些序列的数据点的数量不同。”
这是因为两张表上的时间不同导致的吧,该怎样解决?附上部分代码:mytype = checkedListBox1.SelectedItem.ToString();
SeriesMethod(ref mytype);//因为是动态生成,所以我把对series相关的配置写成了方法
_commandstr = "SELECT time, voltage FROM" + " dbo." + checkedListBox1.SelectedItem.ToString() + " ORDER BY time";
_sqlcommand = new SqlCommand(_commandstr, _AddDase.Getcon());
SqlDataReader sdr = _sqlcommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series[checkedListBox1.SelectedItem.ToString()].Points.DataBindXY(sdr, "time", sdr, "voltage");
chart1.ChartAreas["ChartArea1"].AxisY.Enabled = AxisEnabled.False;
chart1.Series[checkedListBox1.SelectedItem.ToString()].YAxisType = AxisType.Secondary;
chart1.Series[checkedListBox1.SelectedItem.ToString()].XAxisType = AxisType.Primary;
chart1.Series[checkedListBox1.SelectedItem.ToString()].IsXValueIndexed = false;
sdr.Close();
_AddDase.closedatabase();
这张表中有两个series(也有两条线),数据来源于不同的两张表(node_002_temperature与node_003_temperature),但X轴均为时间
当其中一个series已经存在于chart中时,再添加另一个series时会提示;
“如果索引序列(XValueIndexed = true)不对齐,则无法在同一个轴上显示它们。序列“node_002_temperature”和序列“node_003_temperature”必须对齐才能执行此操作。当前这些序列的数据点的数量不同。”
这是因为两张表上的时间不同导致的吧,该怎样解决?附上部分代码:mytype = checkedListBox1.SelectedItem.ToString();
SeriesMethod(ref mytype);//因为是动态生成,所以我把对series相关的配置写成了方法
_commandstr = "SELECT time, voltage FROM" + " dbo." + checkedListBox1.SelectedItem.ToString() + " ORDER BY time";
_sqlcommand = new SqlCommand(_commandstr, _AddDase.Getcon());
SqlDataReader sdr = _sqlcommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.Series[checkedListBox1.SelectedItem.ToString()].Points.DataBindXY(sdr, "time", sdr, "voltage");
chart1.ChartAreas["ChartArea1"].AxisY.Enabled = AxisEnabled.False;
chart1.Series[checkedListBox1.SelectedItem.ToString()].YAxisType = AxisType.Secondary;
chart1.Series[checkedListBox1.SelectedItem.ToString()].XAxisType = AxisType.Primary;
chart1.Series[checkedListBox1.SelectedItem.ToString()].IsXValueIndexed = false;
sdr.Close();
_AddDase.closedatabase();
晕,打错了.... 求解答
主要是你数据有问题,你可以检查数据,是不是显示的数据中有一个为null。不行的话可以联系我。我帮你解决。