End IfEnd SubPrivate Sub Command2_Click() If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2) <> "" And IsNull(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)) = False Then '该表格有数据 With MSChart1 .ChartType = VtChChartType2dBar .ColumnCount = 2 .RowCount = MSHFlexGrid1.Rows - 1 .RowCount = 1 .TitleText = "直方图示例 本旬出口数量与去年同期对比值" Dim XXX, XXXX As Double For I = 1 To MSHFlexGrid1.Rows - 1 XXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)) XXXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)) .Column = 1 .Row = 1 .Data = XXX .Column = 2 .Row = 1 .Data = XXXX .RowLabel = MSHFlexGrid1.TextMatrix(I, 1) .RowLabel = "" Next I .Column = 1 .ColumnLabel = "本旬出口数量" .Column = 2 .ColumnLabel = "去年同期对比百分数" End With End If End Sub
这是MS的例子,希望对你有点用,其他的属性和方法还是请你参考MSDNPrivate Sub Command1_Click() With MSChart1 ' Displays a 3d chart with 8 columns and 8 rows ' data. .ChartType = VtChChartType3dBar .ColumnCount = 8 .RowCount = 8 For column = 1 To 8 For row = 1 To 8 .Column = column .Row = row .Data = row * 10 Next row Next column ' Use the chart as the backdrop of the legend. .ShowLegend = True .SelectPart VtChPartTypePlot, index1, index2, _ index3, index4 .EditCopy .SelectPart VtChPartTypeLegend, index1, _ index2, index3, index4 .EditPaste End With End Sub
Private Sub cmdFormat_Click() ' 首先,将图表类型改为 3D 图表 ' 这样可以看到图的所有部分。 MSChart1.chartType = VtChChartType3dArea ' 用 Plot 对象将 ' 背景变为浅蓝色。 With MSChart1.Plot.Backdrop ' 除非将样式属性正确地设置为VtFillStyleBrush ' 否则不会有颜色显示。 .Fill.Style = VtFillStyleBrush .Fill.Brush.FillColor.Set 100, 255, 200 ' 添加边框。 .Frame.Style = VtFrameStyleThickInner ' 将样式设置为显示阴影。 .Shadow.Style = VtShadowStyleDrop End With '将绘图墙的颜色设置为黄色。 With MSChart1.Plot ' 将样式设置为实心。 .Wall.Brush.Style = VtBrushStyleSolid ' 将颜色设置为黄色。 .Wall.Brush.FillColor.Set 255, 255, 0 End With
With MSChart1.Plot '将绘图底色设置为蓝色。 .PlotBase.BaseHeight = 200 .PlotBase.Brush.Style = VtBrushStyleSolid .PlotBase.Brush.FillColor.Set 0, 0, 255 End With End Sub
下面的示例显示一个具有 8 行 8 列数据的三维图表,并设置了图例的参数。Private Sub Command1_Click() With MSChart1 '显示一个具有 8 行 8 列数据的三维图表。 .ChartType = VtChChartType3dBar .ColumnCount = 8 .RowCount = 8 For column = 1 To 8 For row = 1 To 8 .Column = column .Row = row .Data = row * 10 Next row Next column '将图表作为图例的背景。 .ShowLegend = True .SelectPart VtChPartTypePlot, index1, index2, _ index3, index4 .EditCopy .SelectPart VtChPartTypeLegend, index1, _ index2, index3, index4 .EditPaste End With End Sub
你可以到Office安装目录下有GRAPH9.CHM文件,你S一下。
If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2) <> "" And IsNull(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)) = False Then '该表格有数据
With MSChart1
.ChartType = VtChChartType2dPie
.ColumnCount = 2
.RowCount = 1
Dim XXX As Double
XXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
.TitleText = "饼图示例 完成百分比"
.Column = 1
.Row = 1
.Data = XXX
.ColumnLabel = "完成百分比" & str(XXX) & "%"
.Column = 2
.Row = 1
.Data = 100 - XXX
.ColumnLabel = "剩余百分比" & str(100 - XXX) & "%"
End With
' With MSChart1
' .ChartType = VtChChartType2dPie
' .ColumnCount = 2
' .RowCount = 1
' Dim XXX As Double
' XXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
' .TitleText = "饼图示例 完成百分比"
' .Column = 1
' .Row = 1
' .Data = XXX
' .ColumnLabel = "完成百分比" & Str(XXX) & "%"
' .Column = 2
' .Row = 1
' .Data = 100 - XXX
' .ColumnLabel = "剩余百分比" & Str(100 - XXX) & "%"
' End With
End IfEnd SubPrivate Sub Command2_Click()
If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2) <> "" And IsNull(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2)) = False Then '该表格有数据
With MSChart1
.ChartType = VtChChartType2dBar
.ColumnCount = 2
.RowCount = MSHFlexGrid1.Rows - 1
.RowCount = 1
.TitleText = "直方图示例 本旬出口数量与去年同期对比值"
Dim XXX, XXXX As Double
For I = 1 To MSHFlexGrid1.Rows - 1
XXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
XXXX = Val(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 2))
.Column = 1
.Row = 1
.Data = XXX
.Column = 2
.Row = 1
.Data = XXXX
.RowLabel = MSHFlexGrid1.TextMatrix(I, 1)
.RowLabel = ""
Next I
.Column = 1
.ColumnLabel = "本旬出口数量"
.Column = 2
.ColumnLabel = "去年同期对比百分数"
End With
End If
End Sub
With MSChart1
' Displays a 3d chart with 8 columns and 8 rows
' data.
.ChartType = VtChChartType3dBar
.ColumnCount = 8
.RowCount = 8
For column = 1 To 8
For row = 1 To 8
.Column = column
.Row = row
.Data = row * 10
Next row
Next column
' Use the chart as the backdrop of the legend.
.ShowLegend = True
.SelectPart VtChPartTypePlot, index1, index2, _
index3, index4
.EditCopy
.SelectPart VtChPartTypeLegend, index1, _
index2, index3, index4
.EditPaste
End With
End Sub
' 首先,将图表类型改为 3D 图表
' 这样可以看到图的所有部分。
MSChart1.chartType = VtChChartType3dArea ' 用 Plot 对象将
' 背景变为浅蓝色。
With MSChart1.Plot.Backdrop
' 除非将样式属性正确地设置为VtFillStyleBrush
' 否则不会有颜色显示。
.Fill.Style = VtFillStyleBrush
.Fill.Brush.FillColor.Set 100, 255, 200
' 添加边框。
.Frame.Style = VtFrameStyleThickInner
' 将样式设置为显示阴影。
.Shadow.Style = VtShadowStyleDrop
End With '将绘图墙的颜色设置为黄色。
With MSChart1.Plot
' 将样式设置为实心。
.Wall.Brush.Style = VtBrushStyleSolid
' 将颜色设置为黄色。
.Wall.Brush.FillColor.Set 255, 255, 0
End With
With MSChart1.Plot '将绘图底色设置为蓝色。
.PlotBase.BaseHeight = 200
.PlotBase.Brush.Style = VtBrushStyleSolid
.PlotBase.Brush.FillColor.Set 0, 0, 255
End With
End Sub
With MSChart1
'显示一个具有 8 行 8 列数据的三维图表。
.ChartType = VtChChartType3dBar
.ColumnCount = 8
.RowCount = 8
For column = 1 To 8
For row = 1 To 8
.Column = column
.Row = row
.Data = row * 10
Next row
Next column
'将图表作为图例的背景。
.ShowLegend = True
.SelectPart VtChPartTypePlot, index1, index2, _
index3, index4
.EditCopy
.SelectPart VtChPartTypeLegend, index1, _
index2, index3, index4
.EditPaste
End With
End Sub