来自Legend的Openpyxl隐藏系列数据点

时间:2017-03-22 15:06:39

标签: python openpyxl

我有一张使用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中的示例进行操作,但是我无法找到有关隐藏图例信息的具体内容。

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

3 个答案:

答案 0 :(得分:5)

我必须深入研究源代码,文档严重缺乏。

尝试:

chart1.legend = None

答案 1 :(得分:1)

我认为您需要设置chart.legend.delete = True

答案 2 :(得分:-1)

nope是上一个

chartcol_geologicaprog.legend =无