Specify color for data series in charts

Issue #555 resolved
Johan Abbors created an issue

Hi,

I've been browsing the documentation/code but I specifying color for data series in a chart seems to be missing.

Would be it possible to request this feature?

BR,

Johan

Comments (10)

  1. CharlieC

    You might want to do a checkout and build the docs. I added some stuff yesterday along those lines. But basically it would be great to have users submit docs as I'll only document the stuff I use.

  2. Johan Abbors reporter

    Thanks for the answer. Although, I tested the sample code in the docs and nothing seems to change. I even tested to change the background and foreground color, but nothing changed. The code runs fine.

    I have attached screens shots to illustrate the result opened with different excel software.

    Excel for OSX

    ExeclForOSX.png

    Excel Online

    ExcelOnline.png

    LibreOffice 5.0.3 For OSX

    LibreOffice5.0.3ForOSX.png

  3. Johan Abbors reporter

    It's the code you added in docs/charts/pattern.py

    from openpyxl import Workbook
    from openpyxl.chart import BarChart, Reference
    from openpyxl.chart.marker import DataPoint
    
    from openpyxl.drawing.fill import PatternFillProperties, ColorChoice
    
    wb = Workbook()
    ws = wb.active
    
    rows = [
        ("Sample",),
        (1,),
        (2,),
        (3,),
        (2,),
        (3,),
        (3,),
        (1,),
        (2,),
    ]
    
    for r in rows:
        ws.append(r)
    
    
    c = BarChart()
    data = Reference(ws, min_col=1, min_row=1, max_row=8)
    c.add_data(data, titles_from_data=True)
    c.title = "Chart with patterns"
    
    # set a pattern for the whole series
    series = c.series[0]
    fill =  PatternFillProperties(prst="pct5")
    fill.foreground = ColorChoice(prstClr="red")
    fill.background = ColorChoice(prstClr="blue")
    series.graphicalProperties.pattFill = fill
    
    # set a pattern for a 6th data point (0-indexed)
    pt = DataPoint(idx=5)
    pt.graphicalProperties.pattFill = PatternFillProperties(prst="ltHorz")
    series.dPt.append(pt)
    
    ws.add_chart(c, "C1")
    
    wb.save("pattern.xlsx")
    
  4. Johan Abbors reporter

    But it turns out I didn't test with the latest checkout.

    I'm used to git pull checking out the lastest version and merging it but hg pull does not.

  5. T

    OpenOffice Calc displays it as expected. But MS Excel and Web Excel preview show the views as above with just blue.

  6. Log in to comment