为条形图中的系列添加边框
Adding border to series in a bar chart
我正在使用宏将图表插入电子表格:
Option Explicit
Sub Macro1()
Dim overskrifter As Range
Dim i As Long
Dim høgde As Long, breidde As Long
Call fjernkurver
i = 1
høgde = 240: breidde = 350
Set overskrifter = Oppsummering.Range("C5:L5")
With Kurver.Shapes.AddChart2(201, xlColumnClustered)
.Name = "Graf_" & i
With .Chart.SeriesCollection.NewSeries
.XValues = overskrifter
.Values = overskrifter.Offset(i, 0)
.Name = Oppsummering.Range("B5").Offset(i, 0)
' "Olive"
.Points(1).Format.Fill.ForeColor.RGB = RGB(128, 128, 0)
' "Dark khaki"
.Points(8).Format.Fill.ForeColor.RGB = RGB(189, 183, 107)
' Green (Atlantis)
.Points(9).Format.Fill.ForeColor.RGB = RGB(146, 208, 80)
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
'.ForeColor.RGB = RGB(0, 0, 205)
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
.Height = høgde
.Width = breidde
.Top = 5 + ((i - 1) \ 3) * (5 + høgde)
.Left = 5 + ((i - 1) Mod 3) * (5 + breidde)
.Chart.HasTitle = True
.Chart.ChartGroups(1).GapWidth = 150
.Chart.ChartGroups(1).Overlap = 0
End With
End Sub
Sub fjernkurver()
Dim co As ChartObject
For Each co In Kurver.ChartObjects
co.Delete
Next co
End Sub
大部分情况下它工作正常,但我在这部分代码中遇到了一些问题:
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
'.ForeColor.RGB = RGB(0, 0, 205)
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
应该在图表中的所有条形周围添加边框,红色为 RGB(255,0,0),蓝色为 RGB(0,0,255)。
但是,据我所知,任何条形图都没有添加边框。有人可以指出我哪里出错了吗?
图表最终看起来像这样:
似乎系列的 .Format.Line
属性 适用于条形图边框之外的其他东西 - 猜测是它是连接数据点的线,例如折线图或散点图。
为了实际勾勒出条形图,我替换了有问题的代码;
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
和
.Border.LineStyle = xlContinuous
.Border.Color = 9851952
.Format.Line.Weight = 0.5
请不要问我为什么 .Format.Line.Weight
仍然适用于边界,至少我让它工作了。对写 the thread where I found the answer on Ozgrid forums.
的人的大力支持
我正在使用宏将图表插入电子表格:
Option Explicit
Sub Macro1()
Dim overskrifter As Range
Dim i As Long
Dim høgde As Long, breidde As Long
Call fjernkurver
i = 1
høgde = 240: breidde = 350
Set overskrifter = Oppsummering.Range("C5:L5")
With Kurver.Shapes.AddChart2(201, xlColumnClustered)
.Name = "Graf_" & i
With .Chart.SeriesCollection.NewSeries
.XValues = overskrifter
.Values = overskrifter.Offset(i, 0)
.Name = Oppsummering.Range("B5").Offset(i, 0)
' "Olive"
.Points(1).Format.Fill.ForeColor.RGB = RGB(128, 128, 0)
' "Dark khaki"
.Points(8).Format.Fill.ForeColor.RGB = RGB(189, 183, 107)
' Green (Atlantis)
.Points(9).Format.Fill.ForeColor.RGB = RGB(146, 208, 80)
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
'.ForeColor.RGB = RGB(0, 0, 205)
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
End With
.Height = høgde
.Width = breidde
.Top = 5 + ((i - 1) \ 3) * (5 + høgde)
.Left = 5 + ((i - 1) Mod 3) * (5 + breidde)
.Chart.HasTitle = True
.Chart.ChartGroups(1).GapWidth = 150
.Chart.ChartGroups(1).Overlap = 0
End With
End Sub
Sub fjernkurver()
Dim co As ChartObject
For Each co In Kurver.ChartObjects
co.Delete
Next co
End Sub
大部分情况下它工作正常,但我在这部分代码中遇到了一些问题:
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
'.ForeColor.RGB = RGB(0, 0, 205)
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
应该在图表中的所有条形周围添加边框,红色为 RGB(255,0,0),蓝色为 RGB(0,0,255)。
但是,据我所知,任何条形图都没有添加边框。有人可以指出我哪里出错了吗?
图表最终看起来像这样:
似乎系列的 .Format.Line
属性 适用于条形图边框之外的其他东西 - 猜测是它是连接数据点的线,例如折线图或散点图。
为了实际勾勒出条形图,我替换了有问题的代码;
With .Format.Line
.Visible = msoTrue
.Weight = 0.5
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0
End With
和
.Border.LineStyle = xlContinuous
.Border.Color = 9851952
.Format.Line.Weight = 0.5
请不要问我为什么 .Format.Line.Weight
仍然适用于边界,至少我让它工作了。对写 the thread where I found the answer on Ozgrid forums.