c# chart 控件 Excel数据绑定问题
本帖最后由 lnj_10000 于 2014-03-26 21:40:01 编辑
问题描述:
C#winform 调用指定路径的Excel表格中的数据,绑定到chart控件中显示出条形图加载到form中,程序总是出错 不清楚怎么回事 请高手指点
// Create a Chart
Chart1 = new Chart();
// Create Chart Area
ChartArea chartArea1 = new ChartArea();
// Add Chart Area to the Chart
Chart1.ChartAreas.Add(chartArea1);
// Create a data series
Series series1 = new Series();
//Add series to the chart
Chart1.Series.Add(series1);
string fileNameString = "F:\\works\\大神.xlsx";
// Create connection object by using the preceding connection string.
string sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
fileNameString + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
OleDbConnection myConnection = new OleDbConnection(sConn);
myConnection.Open();
// The code to follow uses a SQL SELECT command to display the data from the worksheet.
// Create new OleDbCommand to return data from worksheet.
OleDbCommand myCommand = new OleDbCommand("Select * From [data1$A1:E7]", myConnection);
// create a database reader
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
Chart1.Series["Default"].Points.DataBindXY(myReader, "1", myReader, "2");
myReader.Close();
myConnection.Close();
// Set chart control location
&n