首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向条形图中的系列添加边框

向条形图中的系列添加边框
EN

Stack Overflow用户
提问于 2018-08-01 20:40:03
回答 1查看 1.1K关注 0票数 0

我使用宏将图表插入到电子表格中:

代码语言:javascript
复制
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

在大多数情况下,它工作得很好,但我对这部分代码有一些问题:

代码语言:javascript
复制
        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)。

但是,据我所知,没有任何边框添加到任何栏。有没有人能指出我哪里出了问题?

图表最终如下所示:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-06 14:08:15

序列的.Format.Line属性似乎适用于条形图的边框之外的其他东西--猜测它是连接线条或散点图数据点的线条。

为了实际勾勒出条形图,我替换了有问题的代码;

代码语言:javascript
复制
With .Format.Line
    .Visible = msoTrue
    .Weight = 0.5
    .ForeColor.RGB = RGB(255, 0, 0)
    .Transparency = 0
End With

使用

代码语言:javascript
复制
.Border.LineStyle = xlContinuous
.Border.Color = 9851952
.Format.Line.Weight = 0.5

请不要问我为什么.Format.Line.Weight仍然适用于边界,至少我让它工作了。给那些写过the thread where I found the answer on Ozgrid forums的人很大的支持。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51633531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档