Openpyxl 隐藏图例中的系列数据点
Openpyxl Hide Series Data Points from Legend
我有一个使用 openpyxl 创建的图表。一切都按预期进行,但是我想隐藏图例中的数据点,同时将它们的格式保留在图表中。简而言之,我想 hide/remove 图表右侧的所有数据点,同时保留条形图的颜色。
这是用于构建图表的代码片段:
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 中的示例进行操作,但是我找不到任何关于隐藏图例信息的具体信息。
我的问题是,我需要关闭什么 members/attributes 才能隐藏数据点,使其不显示在我的图例上,同时保留条形图的颜色?
我认为你需要设置chart.legend.delete = True
我不得不深入研究源代码,文档严重缺乏。
尝试:
chart1.legend = None
不是前一个
chartcol_geologicaprog.legend = None
我有一个使用 openpyxl 创建的图表。一切都按预期进行,但是我想隐藏图例中的数据点,同时将它们的格式保留在图表中。简而言之,我想 hide/remove 图表右侧的所有数据点,同时保留条形图的颜色。
这是用于构建图表的代码片段:
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 中的示例进行操作,但是我找不到任何关于隐藏图例信息的具体信息。
我的问题是,我需要关闭什么 members/attributes 才能隐藏数据点,使其不显示在我的图例上,同时保留条形图的颜色?
我认为你需要设置chart.legend.delete = True
我不得不深入研究源代码,文档严重缺乏。
尝试:
chart1.legend = None
不是前一个
chartcol_geologicaprog.legend = None