下面的代码以cht开始,假设已经使用上面介绍的代码引用了图表。 cht.ChartType = xlArea cht.ChartType = xlLine cht.ChartType = xlPie cht.ChartType = xlColumnClustered cht.ChartType = xlColumnStacked cht.ChartType = xlColumnStacked100 cht.ChartType = xlArea cht.ChartType = xlAreaStacked cht.ChartType = xlBarClustered cht.ChartType = xlBarStacked cht.ChartType = xlBarStacked100
'创建一个嵌入到工作表中的空图表 Set cht = Sheets('Sheet1').Shapes.AddChart2.Chart
Dim rng As Range Set rng = Sheets('Sheet1').Range('A1:B4') cht.SetSourceData Source:=rng
If TypeName(cht.Parent) = 'ChartObject' Then cht.Parent.Delete ElseIf TypeName(cht.Parent) = 'Workbook' Then cht.Delete End If
'设置图表对象的大小/位置-方法1 cht.Parent.Height = 200 cht.Parent.Width = 300 cht.Parent.Left = 20 cht.Parent.Top = 20
'设置图表对象的大小/位置-方法2 chtObj.Height = 200 chtObj.Width = 300 chtObj.Left = 20 chtObj.Top = 20
'修改设置仅显示可见单元格 cht.PlotVisibleOnly = False
'改变两个条形之间的间隙空间 cht.ChartGroups(1).GapWidth = 50
cht.ChartGroups(1).Overlap = 75
cht.ChartArea.Format.Line.Visible = msoFalse
'设置图表区域填充颜色 cht.ChartArea.Format.Fill.ForeColor.RGB = RGB(255, 0, 0) '设置图表没有背景颜色 cht.ChartArea.Format.Fill.Visible = msoFalse 4.xlCategory,
xlSecondary在下面的例子中,这些可以互换使用。为了使代码适应你的特定需求,需要更改括号中引用的图表坐标轴。所有的代码以cht开始,假设已经使用上面介绍的代码引用了图表。cht.Axes(xlValue).MaximumScale = 25 cht.Axes(xlValue).MinimumScale = 10 cht.Axes(xlValue).MaximumScaleIsAuto = True cht.Axes(xlValue).MinimumScaleIsAuto = True
'显示坐标轴 cht.HasAxis(xlCategory) = True '隐藏坐标轴 cht.HasAxis(xlValue, xlSecondary) = False
'显示坐标轴标题 cht.Axes(xlCategory, xlSecondary).HasTitle = True '隐藏坐标轴标题 cht.Axes(xlValue).HasTitle = False
cht.Axes(xlCategory).AxisTitle.Text = '我的坐标轴标题'
'反转分类轴的顺序 cht.Axes(xlCategory).ReversePlotOrder = True '设置分类轴为默认顺序 cht.Axes(xlCategory).ReversePlotOrder = False 欢迎在下面留言,完善本文内容,让更多的人学到更完美的知识。 欢迎到知识星球:完美Excel社群,进行技术交流和提问,获取更多电子资料,并通过社群加入专门的微信讨论群,更方便交流。
|