New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: Iterating through charts #197

Closed
rlecover opened this Issue Dec 16, 2014 · 3 comments

Comments

2 participants
@rlecover

I'm trying to add more than one chart from a previously created list of charts to a worksheet.
I am using xlsxwriter version 0.6.4 and python version 3.4.

Here is some code that demonstrates the problem:

import xlsxwriter

print(xlsxwriter.__version__)


def createChart(workbook):
    chart = workbook.add_chart({'type': 'scatter','subtype': 'straight_with_markers'})
    print("Created new chart " + str(chart))
    return chart

def make_worksheet(workbook):
    worksheet = workbook.add_worksheet()
    charts = list()
    charts.append(createChart(workbook))
    charts.append(createChart(workbook))

    #print(len(charts))

    print(charts)

    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])

    for m in [0,len(charts)-1]:
        currchart= charts[m]
        currchart.add_series({'values': '=Sheet1!$A$1:$A$5', 'catagories': '=Sheet1!$B$1:$B$5'})
        worksheet.insert_chart('E9', currchart)
    return workbook


def main():
    workbook = xlsxwriter.Workbook("demo.xlsx")
    workbook = make_worksheet(workbook)
    workbook.close()
main()  

Here is the output:

0.6.4
Created new chart <xlsxwriter.chart_scatter.ChartScatter object at 0x002BB410>
Created new chart <xlsxwriter.chart_scatter.ChartScatter object at 0x002BB530>
[<xlsxwriter.chart_scatter.ChartScatter object at 0x002BB410>, <xlsxwriter.chart
_scatter.ChartScatter object at 0x002BB530>]
Traceback (most recent call last):
  File "demo.py", line 41, in <module>
    main()
  File "demo.py", line 40, in main
    workbook.close()
  File "c:\Python34\lib\site-packages\xlsxwriter\workbook.py", line 286, in clos
e
    self._store_workbook()
  File "c:\Python34\lib\site-packages\xlsxwriter\workbook.py", line 509, in _sto
re_workbook
    xml_files = packager._create_package()
  File "c:\Python34\lib\site-packages\xlsxwriter\packager.py", line 135, in _cre
ate_package
    self._write_chart_files()
  File "c:\Python34\lib\site-packages\xlsxwriter\packager.py", line 213, in _wri
te_chart_files
    chart._assemble_xml_file()
  File "c:\Python34\lib\site-packages\xlsxwriter\chart.py", line 566, in _assemb
le_xml_file
    self._write_chart()
  File "c:\Python34\lib\site-packages\xlsxwriter\chart.py", line 1321, in _write
_chart
    self._write_plot_area()
  File "c:\Python34\lib\site-packages\xlsxwriter\chart_scatter.py", line 185, in
 _write_plot_area
    self._write_chart_type({'primary_axes': 1})
  File "c:\Python34\lib\site-packages\xlsxwriter\chart_scatter.py", line 65, in
_write_chart_type
    self._write_scatter_chart(args)
  File "c:\Python34\lib\site-packages\xlsxwriter\chart_scatter.py", line 113, in
 _write_scatter_chart
    self._write_ser(data)
  File "c:\Python34\lib\site-packages\xlsxwriter\chart_scatter.py", line 160, in
 _write_ser
    self._write_x_val(series)
  File "c:\Python34\lib\site-packages\xlsxwriter\chart_scatter.py", line 228, in
 _write_x_val
    data = self.formula_data[data_id]
TypeError: list indices must be integers, not NoneType

@jmcnamara jmcnamara self-assigned this Dec 16, 2014

@jmcnamara jmcnamara added invalid question and removed invalid labels Dec 16, 2014

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 16, 2014

Owner

Hi,

You have a typo here in catagories:

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

It should be:

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

Regards,

John

Owner

jmcnamara commented Dec 16, 2014

Hi,

You have a typo here in catagories:

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

It should be:

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

Regards,

John

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Dec 16, 2014

Owner

I've enabled a warning for this on master. Now if the user makes a typo like this, or omits the categories on a scatter chart the following warning is shown:

chart.py:122: UserWarning: Must specify 'categories' in add_series() for this chart type
  warn("Must specify 'categories' in add_series() "
Owner

jmcnamara commented Dec 16, 2014

I've enabled a warning for this on master. Now if the user makes a typo like this, or omits the categories on a scatter chart the following warning is shown:

chart.py:122: UserWarning: Must specify 'categories' in add_series() for this chart type
  warn("Must specify 'categories' in add_series() "
@rlecover

This comment has been minimized.

Show comment
Hide comment

Thanks!

@rlecover rlecover closed this Dec 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment