Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Chart= Forms("窗口2").Controls("Chart1") ' 引用窗口中的图表
Chart.SeriesList.Clear() '清除图表原来的图系
chart.AxisX.ClearValueLabel '清除所有通过SetValueLabel设置的数值字符标示
Dim t As Table = Tables("历史数据2") '定义一个变量t引用数据表
Dim max As Single = t.Compute("Max(最高价)")
Dim min As Single = t.Compute("Min(最低价)")
With t
For i As Integer = 0 To .Count - 1
.Rows(i)("序号") = i
Next
End With
Chart.ChartType = ChartTypeEnum.Candle '设置图表类型
Chart.AxisX.Text = "日期"
Chart.AxisY.Text = "价格"
Chart.AxisY.Min = min '指定Y轴的最小值
Chart.AxisY.Max = max '指定Y轴的最大值
Series = Chart.SeriesList.Add() '增加一个图系
Series.LineColor = Color.Blue '设置该图系的颜色
Series.Length = n2 '设置图系的长度
Chart.AxisX.Min = -1 '指定X轴的最小值
Chart.AxisX.Max = n2 - n1 + 1 '指定X轴的最大值
Series.MarkSize = 12 '设置图系的大小
For i As Integer = 0 To t.Rows.Count - 1 '指定每个数据点的位置
Series.X(i) = t.Rows(i)("序号") '指定水平坐标
Series.Y(i) = t.Rows(i)("最高价") '指定垂直坐标
Series.Y1(i) = t.Rows(i)("最低价") '指定垂直坐标
Series.Y2(i) = t.Rows(i)("开盘价") '指定垂直坐标
Series.Y3(i) = t.Rows(i)("收盘价") '指定垂直坐标
Next
'用第二个图表显示成交额
Dim max2 As Single = t.Compute("Max(成交金额)")
Dim min2 As Single = t.Compute("Min(成交金额)")
Chart.ChartType2 = ChartTypeEnum.Bar '设置图表类型
Chart.SeriesList2.Clear() '清除图表原来的图系
Chart.AxisY2.Min = min2 '指定Y轴的最小值
Chart.AxisY2.Max = max2 '指定Y轴的最大值
Series = Chart.SeriesList2.Add() '增加一个图系
Series.FillColor = Color.LightBlue '设置条形图的填充颜色
For i As Integer = 0 To t.Rows.Count - 1 '指定每个数据点的位置
Series.X(i) = t.Rows(i)("序号")
Series.Y2(i) = t.Rows(i)("成交金额")
Next
Chart.AxisY2.Text = "成交金额"
Chart.AxisY2.GridMajorVisible = False '隐藏Y2轴的网格线
For i As Integer = 0 To n2 - 1
If i Mod 5 = 0 Then
Chart.AxisX.SetValueLabel(i, t.Rows(i)("日期")) '为给定的数值设置字符表示
End If
Next
Chart.AxisX.AnnoWithLabels = True '将用SetValueLabel方法设置的字符来标记刻度.
此主题相关图片如下:捕获.png