Openpyxl从图例中隐藏系列数据点

2024-06-26 08:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我用openpyxl创建了一个图表。一切都如预期的那样,但是我想在保持图表格式的同时隐藏图例中的数据点。简而言之,我想隐藏/删除图表右侧的所有数据点,同时保留条形图的颜色。enter image description here

以下是用于构建图表的代码片段:

chart1 = BarChart()
series = chart1.series[0]

ndcs = Set()
scfs = Set()

for i, row in enumerate(results):
    if 'DNDC' in row[0]: ndcs.add(i-1)
    if 'DSCF' in row[0]: scfs.add(i-1)


for index in ndcs:
    fill =  PatternFillProperties(prst="pct5")
    fill.background = ColorChoice(prstClr="red")

    pt = DataPoint(idx=index)
    pt.graphicalProperties.pattFill = fill
    series.dPt.append(pt)

for index in scfs:
    fill =  PatternFillProperties(prst="pct5")
    fill.background = ColorChoice(prstClr="blue")

    pt = DataPoint(idx=index)
    pt.graphicalProperties.pattFill = fill
    series.dPt.append(pt)

FWIW,我试图按照文档here中的示例进行操作,但是我找不到任何关于隐藏图例信息的具体内容。在

我的问题是,在保留条形图颜色的同时,我需要关闭哪些成员/属性来隐藏图例上显示的数据点?在


Tags: 数据inptforindex颜色图表fill