gpt4 book ai didi

excel - VBA - 在条形图中写入值

转载 作者:行者123 更新时间:2023-12-04 21:58:33 26 4
gpt4 key购买 nike

所以我有这张通过 VBA 制作的图表

enter image description here

现在我想把数据放在条内,所以它看起来像这样:

enter image description here

你能帮我吗?

我要访问此图表的代码是:

Set rng = ActiveSheet.Range("A" & x & ":C" & (x + 4))
' in brackets (Left, Top, Widht, Height) >> modify according to your needs
Set cht = ActiveSheet.ChartObjects.Add(550, 100 * (i - 4), 300, 100)
With cht
.Chart.SetSourceData Source:=rng
.Chart.PlotBy = xlColumns
.Chart.ChartType = xlBarStacked
.Chart.HasAxis(xlValue) = False
.Chart.HasLegend = False
.Chart.HasTitle = True
.Chart.ChartTitle.Text = Application.Sheets(i).Name
.Chart.ChartTitle.Font.Size = 10
.Chart.Axes(xlValue).HasMajorGridlines = False
.Chart.Parent.Name = Application.Sheets(i).Name
End With
cht.Activate
ActiveChart.ChartGroups(1).GapWidth = 10
With ActiveChart.Axes(xlCategory).TickLabels.Font
.Bold = msoFalse
.Size = 8
End With
Set cht_Series = cht.Chart.SeriesCollection(1)
cht_Series.Format.Fill.ForeColor.RGB = RGB(255, 255, 255)
Set cht_Series = cht.Chart.SeriesCollection(2)
cht_Series.Format.Fill.ForeColor.RGB = RGB(134, 188, 37)

谢谢!

最佳答案

要获得您想要的,您需要在代码末尾添加以下行:

ActiveChart.SeriesCollection(2).HasDataLabels = True

由于您已经定义了一个 seriescollection 对象,因此这也可以:
cht_Series.HasDataLabels = True

关于excel - VBA - 在条形图中写入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39268409/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com