7、支持函数

王朝vb·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

最后我们再来看一下几个用来设置图表外观的函数。

SetChartOptions函数

该函数用来设置图表类型、大小。

Public Sub SetChartOptions(ByVal iXlChartType As xlChartType, _

ByVal iPlotAreaWidth As Integer, ByVal iPlotAreaHeight As Integer)

With oExcelChart

.ChartType = iXlChartType

If (iPlotAreaHeight > 50) Then .PlotArea.Height = iPlotAreaHeight

If (iPlotAreaWidth > 50) Then .PlotArea.Width = iPlotAreaWidth

End With

End Sub

该函数的目的是让用户设置一些重要的图表属性。另外,该函数也为开发者示范了如何在必要的时候显露图表属性使得用户可以访问它。本函数允许用户设置图表类型、图形区的高度和宽度,这些属性的默认值已经由SetChartBaseProps() 和SetChartWithDataProps()这两个函数设置过了。

SetChartTitles函数

该函数设置图表标题、X-轴和Y-轴标题。

Sub SetChartTitles(strMainTitle, strXAxisTitle, strYAxisTitle)

On Error Resume Next

With oExcelChart

'--- 检查并设置图表标题

If (Not IsNull(strMainTitle) And Trim(strMainTitle) < > "") Then

.HasTitle = True

.ChartTitle.Caption = strMainTitle

.ChartTitle.Font.Name = "Verdana"

.ChartTitle.Font.FontStyle = "Bold"

.ChartTitle.Font.Size = 14

End If

'--- 检查并设置X-轴标题

If (Not IsNull(strXAxisTitle) And Trim(strXAxisTitle) < > "") Then

.Axes(xlCategory).HasTitle = True

.Axes(xlCategory).AxisTitle.Characters.Text = strXAxisTitle

.Axes(xlCategory).AxisTitle.Font.Name = "Verdana"

.Axes(xlCategory).AxisTitle.Font.FontStyle = "Bold"

.Axes(xlCategory).AxisTitle.Font.Size = 12

End If

'--- 检查并设置Y-轴标题

If (Not IsNull(strYAxisTitle) And Trim(strYAxisTitle) < > "") Then

.Axes(xlValue).HasTitle = True

.Axes(xlValue).AxisTitle.Characters.Text = strYAxisTitle

.Axes(xlValue).AxisTitle.Font.Name = "Verdana"

.Axes(xlValue).AxisTitle.Font.FontStyle = "Bold"

.Axes(xlValue).AxisTitle.Font.Size = 12

'--- 设置Y-轴标题的方向

.Axes(xlValue).AxisTitle.HorizontalAlignment = xlCenter

.Axes(xlValue).AxisTitle.VerticalAlignment = xlCenter

.Axes(xlValue).AxisTitle.Orientation = xlVertical

End If

End With

End Sub

我们不再具体介绍该函数和后面几个函数的每行代码。该函数的目的是设置图表的各种标题:通过ChartTitile对象设置主标题,通过Axes对象设置X轴和Y轴的标题。窍门在于要设置好Y-轴标题的方向,这通过设置Aces对象内AxisTitle对象的Orientation属性实现。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航