Code Monkey home page Code Monkey logo

Comments (7)

jmcnamara avatar jmcnamara commented on May 10, 2024

Currently only Bar charts are supported. Here is an example:

from xlsxwriter.workbook import Workbook

workbook = Workbook('chart_bar01.xlsx')

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'bar', 'embedded': True})

data = [
    [1, 2, 3, 4, 5],
    [2, 4, 6, 8, 10],
    [3, 6, 9, 12, 15],
]

worksheet.write_column('A1', data[0])
worksheet.write_column('B1', data[1])
worksheet.write_column('C1', data[2])

chart.add_series({'categories': '=Sheet1!$A$1:$A$5',
                  'values':     '=Sheet1!$B$1:$B$5'})

chart.add_series({'categories': '=Sheet1!$A$1:$A$5',
                  'values':     '=Sheet1!$C$1:$C$5})

worksheet.insert_chart('E9', chart)

workbook.close()

The output looks like this:

bar_chart

Formatting and other chart types are in progress. This thread will be updated as they become available.

See the following for a full list of feature that are available in Excel::Writer::XLSX charts that will be added to XlsxWriter.

from xlsxwriter.

nilswagner01 avatar nilswagner01 commented on May 10, 2024

Nice example. I am interested in stacked column charts. Is it planned to add this feature in the near future ?

from xlsxwriter.

jmcnamara avatar jmcnamara commented on May 10, 2024

Yes, column charts will be added next (1-2 days) and they will come with stacked and percent_stacked variants.

For example the above code could be modified with either of the following subtypes:

chart = workbook.add_chart({'type': 'bar',
                            'subtype': 'stacked',
                            'embedded': True})
...
chart = workbook.add_chart({'type': 'bar',
                            'subtype': 'percent_stacked',
                            'embedded': True})

Note, the embedded option may be dropped in the final API since it is implicit (non-embedded chart sheets will use a different add_ method).

from xlsxwriter.

jmcnamara avatar jmcnamara commented on May 10, 2024

This is the full list of chart types and sub-types that will be supported:

  • area
    • stacked
    • percent_stacked
  • bar
    • stacked
    • percent_stacked
  • column
    • stacked
    • percent_stacked
  • scatter
    • straight_with_markers
    • straight
    • smooth_with_markers
    • smooth
  • line (with and without markers)
  • stock
  • radar
    • with_markers
    • filled

from xlsxwriter.

jmcnamara avatar jmcnamara commented on May 10, 2024

Column and Line charts have been added. Here is an example of a stacked column chart:

from xlsxwriter.workbook import Workbook

workbook = Workbook('chart_column02.xlsx')

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'column', 'subtype': 'stacked'})

data = [
    [1, 2, 3, 4, 5],
    [2, 4, 6, 8, 10],
    [3, 6, 9, 12, 15],
]

worksheet.write_column('A1', data[0])
worksheet.write_column('B1', data[1])
worksheet.write_column('C1', data[2])

chart.add_series({'categories': '=Sheet1!$A$1:$A$5',
                  'values':     '=Sheet1!$B$1:$B$5'})

chart.add_series({'categories': '=Sheet1!$A$1:$A$5',
                  'values':     '=Sheet1!$C$1:$C$5'})

worksheet.insert_chart('E9', chart)

workbook.close()

column_chart

from xlsxwriter.

jmcnamara avatar jmcnamara commented on May 10, 2024

All chart types and subtypes have been added. Now working on chart formatting and features.

37/161 integration tests complete.

from xlsxwriter.

jmcnamara avatar jmcnamara commented on May 10, 2024

Charts are now available in the master branch and in PyPI version 0.3.1.

from xlsxwriter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.