Charts problem on excel 2013

Issue #551 resolved
zivziv
created an issue

I created a chart on version 2.3.0. When I open it on LibreOffice there's no problem.

Attached python code, excel file and openXML tool errors

Comments (4)

  1. Charlie Clark

    The following code will work. Note that a DateAxis is not strictly necessary but if this is used then it should be given the same axId as the axis it replaces.

    from openpyxl import Workbook
    from openpyxl.chart import LineChart, Reference, Series
    from openpyxl.chart.axis import DateAxis
    
    from datetime import date
    
    def make_chart():
        wb = Workbook()
        ws = wb.active
        rows = [
            ['Date', 'Batch 1', 'Batch 2', 'Batch 3'],
            [date(2015,9, 1), 40, 0.1, 25],
            [date(2015,9, 2), 40, 0.2, 30],
            [date(2015,9, 3), 50, 0.3, 45],
            [date(2015,9, 4), 30, 0.4, 40],
            [date(2015,9, 5), 25, 0.5, 30],
            [date(2015,9, 6), 20, 0.6, 35],
        ]
        for row in rows:
            ws.append(row)
    
        s1 = Reference(ws, min_col=2, min_row=1, max_row=7)
        s2 = Reference(ws, min_col=3, min_row=1, max_row=7)
        s3 = Reference(ws, min_col=4, min_row=1, max_row=7)
        dates = Reference(ws, min_col=1, min_row=2, max_row=7)
    
        c1 = LineChart()
    
        #c1.x_axis = DateAxis(crossAx=100)
        #c1.x_axis.axId = 10
        c1.x_axis.number_format = 'd-mmm'
        c1.x_axis.title = "Date"
    
        c1.add_data(s1, titles_from_data=True)
        c1.add_data(s3, titles_from_data=True)
        c1.set_categories(dates)
    
        c2 = LineChart()
    
        c2.add_data(s2, titles_from_data=True)
        c2.set_categories(dates)
    
        c2.y_axis.axId = 200
        c2.y_axis.crosses = "max"
    
        c1 += c2
    
        ws.add_chart(c1, "D4")
    
        wb.save("bug551.xlsx")
    
    
    if __name__ == "__main__":
        make_chart()
    
  2. Log in to comment