热力环流教案:关于vb中MSCHART控件画二维线图 - conkeyn - JavaEye技术网站

来源:百度文库 编辑:偶看新闻 时间:2024/05/08 06:56:43

关于vb中MSCHART控件画二维线图

问题如下:使用MSCHART控件做出类似下面这个图形的图来。


经过一些摸索给出如下答案:
PrivateSub Command1_Click()
Dim MyData(0 To 4, 0 To 15) As String
DimiRow As Integer
'损失时间H---第1行
'次品数PCS---第2行
'调机/转型号 H---第3行
'报废 KG---第4行
MyData(1, 0) = "损失时间"
MyData(2, 0) = "次品数"
MyData(3,0) = "调机/转型号"
MyData(4, 0) = "报废"
For i = 1 To 15
MyData(0, i)= i & Space(1) '注意一定要后面的space(1),这样做的目的是为了自动显示成标签(字符串类型)
Next
'第1行数据初始化(注意,为0的数据不要赋值)
iRow = 1
MyData(iRow, 1) = 189:MyData(iRow, 2) = 280: MyData(iRow, 3) = 233
MyData(iRow, 6) = 338:MyData(iRow, 7) = 356
'第2行数据初始化
iRow = 2
MyData(iRow, 1) = 227:MyData(iRow, 2) = 190: MyData(iRow, 3) = 172
MyData(iRow, 6) = 189:MyData(iRow, 7) = 232
'第3行数据初始化
iRow = 3
MyData(iRow, 1) = 72:MyData(iRow, 2) = 145: MyData(iRow, 3) = 120
MyData(iRow, 6) = 140:MyData(iRow, 7) = 205
'第4行数据初始化
iRow = 4
MyData(iRow, 1) =36.01: MyData(iRow, 2) = 37.05: MyData(iRow, 3) = 39.31
MyData(iRow,6) = 32.99: MyData(iRow, 7) = 37.98

With MSChart1
'------------------图线标记外观设置开始----------------------------------------------------------------
ForiRow = 1 To 4 '本循环设置4条线标记的大小,线的粗细
   .Plot.SeriesCollection(iRow).SeriesMarker.Auto = False
    WithMSChart1.Plot.SeriesCollection(iRow).DataPoints.Item(-1).Marker
     .Visible = True: .Pen.Width = 10: .Size = 150
    End With
Next
'下面的语句单独设置每条线标记的图案类型
'第一行标记
iRow = 1
.Plot.SeriesCollection(iRow).DataPoints.Item(-1).Marker.Style= VtMarkerStyleFilledCircle '圆形
'第二行标记
iRow = 2
.Plot.SeriesCollection(iRow).DataPoints.Item(-1).Marker.Style= VtMarkerStyleFilledSquare '方形
'第三行标记
iRow = 3
.Plot.SeriesCollection(iRow).DataPoints.Item(-1).Marker.Style= VtMarkerStyleFilledUpTriangle '三角形
'第四行标记
iRow = 4
.Plot.SeriesCollection(iRow).DataPoints.Item(-1).Marker.Style= VtMarkerStyleStar '*形
'------------------图线标记外观设置结束----------------------------------------------------------------

'------------------图线外观设置开始----------------------------------------------------------------
ForiRow = 1 To 4 '本循环设置4条线的粗细及数据值的显示位置
   .Plot.SeriesCollection(iRow).Pen.Width = 10
   .Plot.SeriesCollection(iRow).DataPoints(-1).DataPointLabel.LocationType =VtChLabelLocationTypeRight
   .Plot.SeriesCollection(iRow).DataPoints(-1).DataPointLabel.VtFont.Size =8
    '原图中不显示第一条数据线的数值
    If iRow = 1 Then.Plot.SeriesCollection(iRow).DataPoints(-1).DataPointLabel.LocationType =VtChLabelLocationTypeNone
Next
'------------------图线外观设置结束----------------------------------------------------------------

'------------------坐标轴外观设置开始----------------------------------------------------------------
'设置X轴外观
.Plot.Axis(VtChAxisIdX).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdX).AxisGrid.MinorPen.Style= VtPenStyleNull
.Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style =VtPenStyleNull
'设置第一Y轴外观
.Plot.Axis(VtChAxisIdY).ValueScale.Auto =False
.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = 380
.Plot.Axis(VtChAxisIdY).ValueScale.MajorDivision= 19
.Plot.Axis(VtChAxisIdY).ValueScale.MinorDivision = 0
.Plot.Axis(VtChAxisIdY).AxisGrid.MinorPen.Style= VtPenStyleNull
.Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style =VtPenStyleNull
'设置第二Y轴外观
.Plot.Axis(VtChAxisIdY2).AxisScale.Hide =True
.Plot.Axis(VtChAxisIdY2).ValueScale.Auto = False
.Plot.Axis(VtChAxisIdY2).AxisGrid.MinorPen.Style= VtPenStyleNull
.Plot.Axis(VtChAxisIdY2).AxisGrid.MajorPen.Style =VtPenStyleNull
'------------------坐标轴外观设置结束----------------------------------------------------------------

'------------------图例外观设置开始----------------------------------------------------------------
.ShowLegend= True
.Legend.Backdrop.Frame.Style = VtFrameStyleSingleLine
.Legend.Backdrop.Frame.Width= 10
.Legend.Location.LocationType = VtChLocationTypeTopRight
'------------------图例外观设置结束----------------------------------------------------------------

'------------------图形区设置开始----------------------------------------------------------------
.Plot.AutoLayout= False
.Plot.LocationRect.Min.Set 0, 0
.Plot.LocationRect.Max.Set.Width, .Height - 850 '减去图例的高度
'------------------图形区设置结束----------------------------------------------------------------


.Plot.DataSeriesInRow= True '设置图形按行读取数据
.chartType = VtChChartType2dLine '设置图表类型
.ChartData= MyData
End With
End Sub

程序运行后效果如下图