excel - Excel/VBA:向圆环图添加标题可减小圆环的大小
问题描述
...但我希望我的甜甜圈是全尺寸的。因为我想将标题移动到甜甜圈的中心,所以我不需要上边距,它似乎是通过Chart.HasTitle = True
. 我该如何解决这个问题?
示例代码
Sub createChart()
If ActiveSheet.ChartObjects.Count > 0 Then ActiveSheet.ChartObjects.Delete
Dim chrt As ChartObject
Dim dataRng As Range
Dim lft As Integer
lft = ActiveSheet.Range("D2").Left
Dim wdth As Integer
wdth = 500
Dim hgt As Integer
hgt = 300
Dim tp As Integer
tp = ActiveSheet.Range("D2").Top
Set chrt = ActiveSheet.ChartObjects.Add(Left:=lft, Width:=wdth, Height:=hgt, Top:=tp)
Dim i As Integer
For i = 1 To 10
ActiveSheet.Cells(i, 1).Value = "A" & i
With ActiveSheet.Cells(i, 2)
.Value = i / 55
.NumberFormat = "0.00%"
End With
Next i
Set dataRng = Range("A1:B10")
With chrt.Chart
.ChartType = xlDoughnut
.SetSourceData Source:=dataRng
' comment out from here
.HasTitle = True
With .ChartTitle
.Text = "Test"
.Top = hgt / 2
.Left = wdth / 2 - 20
End With
' to here
.HasLegend = False
End With
End Sub
解决方案
.ChartTitle.IncludeInLayout = False
在 .后面添加一行.HasTitle = True
。
您可以阅读有关该属性的文档以了解有关其作用的更多详细信息,但基本上您将其设置为
如果在确定图表布局时图表标题将占用图表布局空间,则为真
推荐阅读
- vb.net - 为什么当我处理表单并再次返回时 openFileDialog 没有响应?
- javascript - 如何删除部分媒体记录器?
- python - 用python字典中的整数值替换文本中的值并找到它的总和
- python - AttributeError:导入 BERT 时模块“tensorflow_core._api.v2.train”没有属性“Optimizer”
- javascript - Axios - 如何不将 [] 添加到多参数?
- jquery - 根据 Laravel 中的特定功能自动更新 Slug 字段值
- javascript - 从 PY 到 JS 的成绩单
- c# - 我需要使用 AutoMapper 对这行代码进行单元测试吗?
- spring-boot - Thymeleaf 模板未显示用户名
- node.js - 无法在数组 nodejs 中存储数组