excel - 你怎么能画一个度数相等的“馅饼”?
问题描述
你怎么能画一个度数相等的“馅饼”?
此代码在当前工作表中创建弧线——
Sub Create_arcs()
Dim MyShape As Shape
'Your number of parts in the circle
NumParts = 6
For i = 1 To NumParts
Set MyShape = ActiveSheet.Shapes.AddShape(msoShapeBlockArc, 0.75, 0.75, 146.25, 146.25)
With MyShape
.Adjustments.Item(1) = i * 360 / NumParts
.Adjustments.Item(2) = i * 360 / NumParts + 360 / NumParts
'Size of internal doughnut
'.Adjustments.Item(3) = .2
'Format for each sharpe
.Fill.ForeColor.RGB = RGB(i * 20, i * 20, i * 20)
.Line.ForeColor.RGB = RGB(255, 255, 255)
.Line.Weight = 3
End With
Next i
End Sub
这适用于 Excel,并且可以调整为适用于 PowerPoint,我猜是 Word。
接受有关如何更有效地执行此操作的建议。
解决方案
或者也许 - 多一点思考和适当的缩进:
Option Explicit ' <-- always remember this at the top of modules
Sub Create_arcs(numParts as Long)
Dim iterator as Long
For iterator = 1 To numParts
With ActiveSheet.Shapes.AddShape(msoShapeBlockArc, 0.75, 0.75, 146.25, 146.25)
.Adjustments.Item(1) = iterator * 360 / NumParts
.Adjustments.Item(2) = iterator * 360 / NumParts + 360 / NumParts
'Size of internal doughnut
'.Adjustments.Item(3) = .2
'Format for each shape
.Fill.ForeColor.RGB = RGB(iterator * 20, iterator * 20, iterator * 20)
.Line.ForeColor.RGB = RGB(255, 255, 255)
.Line.Weight = 3
End With
Next iterator
End Sub
当然,我还没有测试过——甚至上面的代码也很容易出错——如果你想要 13 个部分怎么办(提示:考虑哪些代码依赖于部分的数量)?什么是项目 1、2 和 3?也许一些简单的英语会有所帮助。
那么,你怎么能画一个度数相等的“馅饼”呢?
可能是通过设置具有所需数据量的饼图并让本机函数处理问题。
推荐阅读
- sql - 具有重复值的案例语句,Hadoop
- database-normalization - 具有函数依赖关系的依赖关系保持分解不会出现在子模式中
- django - 找不到 PUT 方法的 Django Rest Framwork CSRF cookie
- javascript - 在 Excel 中导出时,欧元符号“€”显示不佳
- powerbuilder - 我正在使用 PowerBuilder,但 (if, or, and) 条件有问题
- python - 如何更快地获得子矩阵块?
- php - 检查 Path 是否指向 DIRECTORY 内部或 path 是 DIRECTORY 的子目录
- php - PHPMailer 在点击提交按钮时将电子邮件发送到不同的地址和不同的正文
- ios - 使用LinkedinSwift的LinkedIn登录突然无法正常工作
- api - 是否可以按属性查找 Wikipedia ID,例如 Grid ID