创建从DataGridView
答
你可以从以下代码得到想法:
private void DataGridBinding_Load(object sender, System.EventArgs e)
{
// Populate series data using random data
double[] yValues = { 23.67, 75.45, 60.45, 34.54, 85.62, 32.43, 55.98, 67.23 };
for(int pointIndex = 0; pointIndex < yValues.Length; pointIndex++)
{
chart1.Series["Series1"].Points.AddXY(1990 + pointIndex, yValues[pointIndex]);
}
// Export series values into DataSet object
dataSet1 = chart1.DataManipulator.ExportSeriesValues("Series1");
// Data bind DataGrid control.
SeriesValuesDataGrid.DataSource = dataSet1;
// Set Series name for data
SeriesValuesDataGrid.DataMember = "Series1";
}
private void SeriesValuesDataGrid_CurrentCellChanged(object sender,System.EventArgs e)
{
// Initializes a new instance of the DataView class
DataView firstView = new DataView(dataSet1.Tables[0]);
// Since the DataView implements IEnumerable, pass the reader directly into
// the DataBind method with the name of the Columns selected in the query
chart1.Series["Series1"].Points.DataBindXY(firstView,"X",firstView,"Y");
// Invalidate Chart
chart1.Invalidate();
}
您可以从Samples Environments for Microsoft Chart Controls 中获取完整的项目代码,并从WorkingWithData> DataManipulation> Exporting> DataGridBinding部分查找代码。
我不知道如何尝试图表,但我填写dataGridView: this.all_Booking_DataTableAdapter.Fill(this.partners_DataSet.All_Booking_Data); – 2014-10-12 10:38:14
您发布的代码中没有'dataGridView'。找到你设置'dataGridView.DataSource'属性的位置,并为'Chart'执行相同的操作。 – Dmitry 2014-10-12 10:43:26
这行代码将数据表单StoredProcedure加载到'partners_DataSet.All_Booking_Data' this.all_Booking_DataTableAdapter.Fill(this.partners_DataSet.All_Booking_Data); – 2014-10-12 10:47:56