vba - 圆弧
问题描述
我试图围绕一个圆圈定位一个弧线,以显示我们的客户在哪个范围内执行。
子构建一个与内圈大小相同的弧,但我无法正确定位它。
我在下面附上了一张图片来证明我的问题。
firstang = shp.Chart.ChartGroups(1).FirstSliceAngle
radius = shp.Chart.PlotArea.Height / 2
Pi = 3.14159265358979
z = 1
j = 1
Debug.Print "Charttype: " & shp.Chart.ChartType
gradfaktor = (360 / Pi)
Breite = shp.Chart.PlotArea.Width + 2 * Abstand + 2 * Balkendicke
breitekreissegment = Balkendicke / Breite * 2
For z = 1 To shp.Chart.SeriesCollection(1).Points.Count
Set newshp = sld.Shapes.AddShape(msoShapeBlockArc, 10, 10, Breite, Breite)
x1 = shp.Chart.SeriesCollection(1).Points(z).PieSliceLocation(xlHorizontalCoordinate, xlOuterClockwisePoint)
y1 = shp.Chart.SeriesCollection(1).Points(z).PieSliceLocation(xlVerticalCoordinate, xlOuterClockwisePoint)
x2 = shp.Chart.SeriesCollection(1).Points(z).PieSliceLocation(xlHorizontalCoordinate, xlOuterCounterClockwisePoint)
y2 = shp.Chart.SeriesCollection(1).Points(z).PieSliceLocation(xlVerticalCoordinate, xlOuterCounterClockwisePoint)
newshp.Fill.ForeColor.RGB = farbe
newshp.Line.Transparency = 1
newshp.name = "B1_" & 1
DoEvents
'newshp.Height = shp.Height
DoEvents
newshp.Left = shp.Left + shp.Chart.PlotArea.Left * 0.5 - Balkendicke
newshp.Top = shp.Top + shp.Chart.PlotArea.Top * 0.5 - Balkendicke
newshp.Adjustments.Item(3) = breitekreissegment
l1 = ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
alpha1 = (2 * ArcSin((l1 / (2 * radius)))) * 180 / Pi
newshp.Adjustments.Item(1) = alpha1
newshp.Adjustments.Item(2) = firstang
DoEvents
firstang = firstang + alpha1 + WinkelAbstand
Next z
chartcount = chartcount + 1
l1 = ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
alpha1 = (2 * ArcSin((l1 / (2 * radius)))) * 180 / Pi
解决方案
你可以做这样的事情,只需制作单独的图表。
Sub test()
Set myCht_01 = ActiveSheet.Shapes.AddChart
Set myCht_02 = ActiveSheet.Shapes.AddChart
With myCht_01
.Chart.ChartType = xlDoughnut
.Chart.SetSourceData Source:=Range("$F$3:$F$4")
.Chart.ChartGroups(1).DoughnutHoleSize = 85
.Chart.Legend.Delete
.Chart.ChartGroups(1).FirstSliceAngle = 180
Set serCol_01 = .Chart.SeriesCollection(1)
With serCol_01
.ApplyDataLabels
For Each lbl In .DataLabels
If lbl.Name = "Text S1P1" Then lbl.Text = "Nein"
If lbl.Name = "Text S1P2" Then lbl.Text = "Ja"
Next lbl
.DataLabels.ShowCategoryName = True
End With
End With
With myCht_02
.Chart.ChartType = xlDoughnut
.Chart.SetSourceData Source:=Range("$E$3:$E$4")
.Line.Visible = msoFalse
.Chart.Legend.Delete
.Chart.SeriesCollection(1).ApplyDataLabels
.Chart.ChartGroups(1).FirstSliceAngle = 270
End With
myCht_02.ScaleWidth 0.75, msoFalse, msoScaleFromMiddle
myCht_02.ScaleHeight 0.75, msoFalse, msoScaleFromMiddle
myCht_02.Fill.Visible = msoFalse
Set shpGroup = ActiveSheet.Shapes.Range(Array(myCht_01.Name, myCht_02.Name)).Group
Exit Sub
shpGroup.Delete
End Sub
推荐阅读
- css - 悬停时的css使用css或javascript在div周围显示多种颜色
- css - 使用 Tailwind CSS 为每个 HTML 生成不同的样式表以用于生产
- kubernetes - kustomize 编辑集图像不适用于 kustomize multibases 和 common base
- cmd - CMD 无法运行没有 .exe 的 exe
- python - 二维 sinc 函数
- go - 类型 ByKey []mr.KeyValue{} 是什么意思?
- server - 文件共享 Windows Server 2016 中的文件损坏
- node.js - Firebase 函数使用 GOOGLE_APPLICATION_CREDENTIALS 部署未能在全局范围内获取环境配置
- javascript - 标头中的数组到字符串转换错误
- java - 从 Java 中的静态表中指向实例方法