您好,这里是从DataTable创建图表的示例代码。
- DataSet _dataSet;
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- // 创建连接并填充数据集
- string mdbFile = @"c:\db\nwind.mdb";
- string connString = string.Format(
- "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}",
- mdbFile);
- OleDbConnection conn = new OleDbConnection(connString);
- OleDbDataAdapter adapter = new OleDbDataAdapter(
- @"SELECT TOP 10 ProductName, UnitPrice FROM Products
- ORDER BY UnitPrice;", conn);
- _dataSet = new DataSet();
- adapter.Fill(_dataSet, "Products");
- // 将数据表列设置为图表数据的数据源
- c1Chart1.Data.ItemsSource = _dataSet.Tables["Products"].Rows;
- }
复制代码- <c1chart:C1Chart.Data>
- <c1chart:ChartData ItemNameBinding="{Binding Path=[ProductName]}">
- <c1chart:DataSeries ValueBinding="{Binding Path=[UnitPrice]}"/>
- </c1chart:ChartData>
- </c1chart:C1Chart.Data>
复制代码 |