Dim dt1 As Date = Forms("窗口1").Controls("DateTimePicker1").Value
Dim dt2 As Date = Forms("窗口1").Controls("DateTimePicker2").Value
'第一个图表
Dim Chart As WinForm.Chart '定义一个图表变量
Dim Series As WinForm.ChartSeries '定义一个图系变量
Chart = Forms("窗口1").Controls("Chart1") ' 引用窗口中的图表
Chart.ChartType = ChartTypeEnum.XYPlot '设置图表类型
Chart.AxisX.DateType = True '明确指定X轴是日期型
Chart.AxisX.AnnoFormatString = "MM-dd" '制定日期表示格式
Chart.SeriesList.Clear() '清除图表原来的图系
Series = Chart.SeriesList.Add() '增加一个图系
Dim drs As List(Of DataRow)
drs = DataTables("表A").Select("日期 >= '" & dt1 & "' And 日期 <= '" & dt2 & "'")
Series.Length = drs.Count '图系n个数据点
For i As Integer = 0 To drs.Count - 1 '遍历所有行
Series.X(i) = drs(i)("日期") '指定水平坐标
Series.Y(i) = drs(i)("预测") '垂直坐标用随机数生成
Next
Series.LineColor = Color.Blue '设置该图系的颜色
Series.MarkShape = MarkShapeEnum.Dot
Series.MarkColor = Color.Green
Series.Text = "预测"
'第二个图表
Chart.ChartType2 = ChartTypeEnum.XYPlot
Chart.SeriesList2.Clear()
Series = Chart.SeriesList2.Add()
Series.Length = drs.Count '图系n个数据点
For i As Integer = 0 To drs.Count - 1 '遍历所有行
Series.X(i) = drs(i)("日期") '指定水平坐标
Series.Y(i) = drs(i)("实际") '垂直坐标用随机数生成
Next
Series.LineColor = Color.Red
Series.MarkShape = MarkShapeEnum.Dot
Series.MarkColor = Color.Yellow
Chart.AxisY.GridMajorVisible = False '隐藏Y2轴的网格线
Series.Text = "实际"
'Chart.AxisX.AnnoWithLabels = True '启用字符标示(启用后不显示日期)
Chart.VisualEffect = True '加上这一行,让你的图表更漂亮
Chart.LegendVisible = True '显示图列
Chart.LegendCompass = CompassEnum.South '图列显示在南方(底端)
此主题相关图片如下:截屏图片 (7).jpg