这个示例展示了如何在运行时刻把图表绑定到 MDB 数据库。
C# | 复制代码 |
---|
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
using DevExpress.XtraCharts;
private void Form1_Load(object sender, EventArgs e) {
ChartControl chart = new ChartControl();
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM GSP",
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\gsp.mdb");
DataSet ds = new DataSet();
adapter.Fill(ds);
chart.DataSource = ds;
chart.DataAdapter = adapter;
chart.SeriesDataMember = "Table.Year";
chart.SeriesTemplate.ArgumentDataMember = "Table.Region";
chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Table.GSP" });
chart.SeriesTemplate.View = new StackedBarSeriesView();
chart.SeriesTemplate.Label.Visible = false;
((StackedBarSeriesView)chart.SeriesTemplate.View).AxisX.Label.Angle = 25;
((StackedBarSeriesView)chart.SeriesTemplate.View).AxisX.Label.Antialiasing = true;
chart.Dock = DockStyle.Fill;
this.Controls.Add(chart);
}
|
Visual Basic | 复制代码 |
---|
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
Handles MyBase.Load
Dim chart As New ChartControl()
Dim adapter As New OleDbDataAdapter("SELECT * FROM GSP", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\gsp.mdb")
Dim ds As New DataSet()
adapter.Fill(ds)
chart.DataSource = ds
chart.DataAdapter = adapter
chart.SeriesDataMember = "Table.Year"
chart.SeriesTemplate.ArgumentDataMember = "Table.Region"
chart.SeriesTemplate.ValueDataMembers.AddRange(New String() { "Table.GSP" })
chart.SeriesTemplate.View = New StackedBarSeriesView()
chart.SeriesTemplate.Label.Visible = False
CType(chart.SeriesTemplate.View, StackedBarSeriesView).AxisX.Label.Angle = 25
CType(chart.SeriesTemplate.View, StackedBarSeriesView).AxisX.Label.Antialiasing = True
chart.Dock = DockStyle.Fill
Me.Controls.Add(chart)
End Sub
|