代码之家  ›  专栏  ›  技术社区  ›  Mike

OpenPYXL设置条形图中条形图的颜色

  •  0
  • Mike  · 技术社区  · 8 年前

    我想用OpenPYXL在条形图中设置条形图的颜色。我创造了以下

    data = Reference(sheet, min_col=3, min_row=6, max_col=4, max_row=10)
    titles = Reference(sheet, min_col=1, min_row=6, max_row=10)
    chart = BarChart3D()
    chart.title = title
    chart.add_data(data=data, titles_from_data=True)
    chart.set_categories(titles)
    

    我在这里找到的 How to set Background Color of Plot Area of Chart using openpyxl 如何使用chart.plot\u area.graphical\u属性更改背景色

    但是,我不知道要改变酒吧的颜色。

    1 回复  |  直到 8 年前
        1
  •  2
  •   Nicolas N    8 年前

    对于我使用的二维绘图 graphicalProperties.line.solidFill graphicalProperties.solidFill :

    wb = load_workbook('data.xlsx')
    ws = wb['sheet1']
    
    chart = BarChart()
    chart.type = "col"
    chart.style = 10
    chart.title = "Chart Title"
    chart.y_axis.title = 'Y Axis'
    chart.x_axis.title = 'X Axis'
    
    data = Reference(ws, min_col=3, min_row=1, max_row=3, max_col=3)
    cats = Reference(ws, min_col=1, min_row=2, max_row=3)
    
    chart.add_data(data, titles_from_data=True)
    chart.set_categories(cats)
    chart.shape = 4
    
    # Change bar filling and line color 
    s = chart.series[0]
    s.graphicalProperties.line.solidFill = "00000"
    s.graphicalProperties.solidFill = "ff9900" 
    
    
    ws.add_chart(chart, "A10")
    wb.save("bar.xlsx")
    

    我希望3D绘图也一样