联机帮助代码
'In this example, the sales for two companies are shown for four months.
'Create the data array and bind it to the ChartData property.
Dim Sales(,) As Object = New Object(, ) _
{{"Company", "Company A", "Company B"}, _
{"June", 20, 10}, _
{"July", 10, 5}, _
{"August", 30, 15}, _
{"September", 14, 7}}
chtSales.ChartData = Sales
'Add a title and legend.
With Me.chtSales
.Title.Text = "Sales"
.Legend.Location.LocationType = _
MSChart20Lib.VtChLocationType.VtChLocationTypeBottom
.Legend.Location.Visible = True
End With
'Add titles to the axes.
With Me.chtSales.Plot
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdX).AxisTitle.Text = "Year"
.Axis(MSChart20Lib.VtChAxisId.VtChAxisIdY).AxisTitle.Text = "Millions of $"
End With
'Set custom colors for the bars.
With Me.chtSales.Plot
'Yellow for Company A
' -1 selects all the datapoints.
.SeriesCollection(1).DataPoints(-1).Brush.FillColor.Set(250, 250, 0)
'Purple for Company B
.SeriesCollection(2).DataPoints(-1).Brush.FillColor.Set(200, 50, 200)
End With
'''
'产生一个数据集
Dim ds As New DataSet
Dim dt As New DataTable
Dim dc As New DataColumn
''''''''Generate A Datatable
'Math : single
dc = New DataColumn
dc.ColumnName = "Math Score"
dc.DataType = System.Type.GetType("System.Single")
dt.Columns.Add(dc)
'English : single
dc = New DataColumn
dc.ColumnName = "English Score"
dc.DataType = System.Type.GetType("System.Single")
dt.Columns.Add(dc)
Dim dr As DataRow
Dim i As Integer
For i = 0 To 10
dr = dt.NewRow
dr.Item(0) = Rnd() * 100
dr.Item(1) = Rnd() * 100
dt.Rows.Add(dr)
Next
dt.TableName = "tblStudent"
ds.Tables.Add(dt)
'''
' Read ChartData from dataset
' Only the first Datatable
'''
Dim ChartData(,) As Object
ReDim ChartData(ds.Tables(0).Rows.Count, ds.Tables(0).Columns.Count)
Dim k, l As Integer
For k = 0 To ds.Tables(0).Rows.Count - 1
For l = 0 To ds.Tables(0).Columns.Count - 1
ChartData(k, l) = ds.Tables(0).Rows(k).Item(l)
Next
Next
Me.AxMSChart1.chartType = MSChart20Lib.VtChChartType.VtChChartType2dXY
Me.AxMSChart1.ChartData = ChartData
'''
'产生一个数据集
Dim ds As New DataSet
Dim dt As New DataTable
Dim dc As New DataColumn
''''''''Generate A Datatable
'Math : single
dc = New DataColumn
dc.ColumnName = "Math Score"
dc.DataType = System.Type.GetType("System.Single")
dt.Columns.Add(dc)
'English : single
dc = New DataColumn
dc.ColumnName = "English Score"
dc.DataType = System.Type.GetType("System.Single")
dt.Columns.Add(dc)
Dim dr As DataRow
Dim i As Integer
For i = 0 To 10
dr = dt.NewRow
dr.Item(0) = Rnd() * 100
dr.Item(1) = Rnd() * 100
dt.Rows.Add(dr)
Next
dt.TableName = "tblStudent"
ds.Tables.Add(dt)
'''
' Read ChartData from dataset
' Only the first Datatable
'''
Dim ChartData(,) As Object
ReDim ChartData(ds.Tables(0).Rows.Count, ds.Tables(0).Columns.Count)
Dim k, l As Integer
For k = 0 To ds.Tables(0).Rows.Count - 1
For l = 0 To ds.Tables(0).Columns.Count - 1
ChartData(k, l) = ds.Tables(0).Rows(k).Item(l)
Next
Next
Me.AxMSChart1.chartType = MSChart20Lib.VtChChartType.VtChChartType2dXY
Me.AxMSChart1.ChartData = ChartData