在 Access 中更改饼图系列的填充颜色

问题描述 投票:0回答:1

我有一个基于此查询的图表。

SELECT IDtrattativa, NomeCognome, [Ricavi] AS Valore, "Redditività" AS CostiRicavi FROM qryAnalisiOperazione
UNION
SELECT IDtrattativa, NomeCognome, [costi], "Costi" FROM  qryAnalisiOperazione;

这是一个系列,这就是我得到的。

我想改变系列中的颜色(costi应该是红色,ricavi应该是绿色)。

我在打开状态下尝试了这段代码(然后我在加载事件中尝试过)。

With Me.CostiRicaviGR.ChartSeriesCollection.Item(0)
    .BorderColor = RGB(123, 222, 100)
    .FillColor = RGB(200, 300, 111)
End With

什么也没发生。

vba ms-access charts pie-chart color-scheme
1个回答
0
投票

我在旧版本的 Access (2016) 中尝试过这个。与 Excel 不同,Access Chart 模型似乎不支持 RGB。但 Access Chart Model 仍然支持 ColorIndex:

' https://learn.microsoft.com/en-us/office/vba/api/excel.interior.colorindex
Private Sub cmdChangeColor_Click()
myGraph.ChartArea.Interior.ColorIndex = 4 'works 'sets the background of the chart
'myGraph.ChartArea.Interior.ColorIndex = RGB(4, 0, 0) 'works cast to 4
myGraph.SeriesCollection(1).Points(1).Interior.ColorIndex = 5 'works 'sets the color of the data
End Sub
'to understand the model think of a pie chart like a line graph.  Each line on the line graph corresponds to a different Series or pie chart.  The first point is the first point on the line or the first piece of the pie.  Interior.ColorIndex sets the color of the line or pie piece.

重要的警告是,我的 Access 中的 Intellisense 既不支持 ChartArea 也不支持 SeriesCollection,当我尝试将 ChartArea 调用包装在函数中以便我可以向其传递参数时,它意外失败。简而言之,这是一个图表对象的 Access 版本远远不如 Excel 版本的示例。更多 Access 程序可以很好地协同工作。

因此,有几次当我在 Access 中需要的不仅仅是基本图表时,我会在幕后打开 Excel 并在那里完成所有操作,然后将完成的图表导入到 Access 中。花了不到一秒钟的时间。 不幸的是,我找不到通过 Access 在 Excel 中制作图表的具体示例,但这里有一个显示基础知识的链接:https://www.youtube.com/watch?v=A5LvSI4dIuc

© www.soinside.com 2019 - 2024. All rights reserved.