调用绑定数据函数,第一句话就出错,说超出索引!求指导…
…………………
…………………
//绑定数据函数
public static void DrawSpline(double []listX , double [] listY, Chart chart1)
{
try
{
//X.Y值成员
chart1.Series[0].Points.DataBindXY(listX, listY);//<–这句话就出错!
//chart1.Series[0].Points.DataBindY(listY);
//点颜色
chart1.Series[0].MarkerColor = Color.Green;
chart1.Series[0].ChartType = SeriesChartType.Spline;
catch
…
}
……………
……………
//调用语句
……………
{
double [] xData = {1,2,3,4,5,6,7,8 };
double[] yData = { 0.2f, 0.3f, 0.1f, 0.4f, 0.1f,0.4f,0.8f,0.5f };
DrawClass.DrawSpline(xData, yData, chart1);
}
…………………
…………………
//绑定数据函数
public static void DrawSpline(double []listX , double [] listY, Chart chart1)
{
try
{
//X.Y值成员
chart1.Series[0].Points.DataBindXY(listX, listY);//<–这句话就出错!
//chart1.Series[0].Points.DataBindY(listY);
//点颜色
chart1.Series[0].MarkerColor = Color.Green;
chart1.Series[0].ChartType = SeriesChartType.Spline;
catch
…
}
……………
……………
//调用语句
……………
{
double [] xData = {1,2,3,4,5,6,7,8 };
double[] yData = { 0.2f, 0.3f, 0.1f, 0.4f, 0.1f,0.4f,0.8f,0.5f };
DrawClass.DrawSpline(xData, yData, chart1);
}
解决方案
20
Series 这个集合里面有内容吗? 如过是直接拖过来的,里面会有个默认的,假如你是手写的,那么就需要手动加一个Series
参考
public void chartDataBind()
{
double[] yValues = { 1, 12, 4,7, 5, 15, 2,11, 6, 10};
double[] xValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
参考
public void chartDataBind()
{
double[] yValues = { 1, 12, 4,7, 5, 15, 2,11, 6, 10};
double[] xValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Series mySerie = new Series(“mySeries”);
chart1.Series.Add(mySerie);
chart1.Series[0].Points.DataBindXY(xValues, yValues);
}