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 with DataLabels Position in Column Chart #170

Closed
MitsuharuEishi opened this Issue Oct 15, 2014 · 3 comments

Comments

2 participants
@MitsuharuEishi

MitsuharuEishi commented Oct 15, 2014

I'm trying to position the data labels at the top of each column in a column chart, however doing so creates an Excel file with invalid XML that Excel won't process. I'm using XlsxWriter version 0.5.7 with Python version 2.7.6.

Here's a sample that will create such a file:

from xlsxwriter import Workbook
import random

book = Workbook('C:\\Temp\\ex.xlsx')
sheet = book.add_worksheet('Will Error')
data_sheet = book.add_worksheet('data')

year_dict = {}
year_list = [2013, 2014]
year = []
month = []
defect_rate = []

# Creates three columns of random data for each month in two years
for y in year_list:
    year_dict[y] = 0
    for m in range(1, 13):
        year.append(y)
        month.append(m)
        defect_rate.append(random.randint(0, 100))
        year_dict[y] += 1

data_sheet.write_column("A1", year)
data_sheet.write_column("B1", month)
data_sheet.write_column("C1", defect_rate)


chart = book.add_chart({'type': 'column'})
chart.add_series({
    'values': ['data', 0, 2, year_dict[2013] - 1, 2],
    'categories': ['data', 0, 1, year_dict[2013] - 1, 1],
    'name': '2013',
    'data_labels': {'value': True, 'position': 'top'}
})
chart.add_series({
    'values': ['data', year_dict[2013], 2, year_dict[2013] + year_dict[2014] - 1, 2],
    'categories': ['data', year_dict[2013], 1, year_dict[2013] + year_dict[2014] - 1, 1],
    'name': '2014',
    'data_labels': {'value': True, 'position': 'top'}
})

chart.set_x_axis({'name': 'Month', 'name_font': {'size': 14, 'bold': True}})
chart.set_size({'width': 800, 'height': 600})
chart.set_title({'name': "Defect Rate By Month"})

sheet.insert_chart('A1', chart)
book.close()
@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Oct 15, 2014

Owner

Hi David,

Thanks for the detailed report.

I was aware of this issue but I only found out about it recently.

In Excel the top position isn't available for column charts. Instead Excel used a position called outside. Changing it to that should fix your issue.

However, this is a bug in XlsxWriter since it should throw a warning or exception when an invalid position is specified.

I'll fix it in the next release.

Thanks for reporting,

John

Owner

jmcnamara commented Oct 15, 2014

Hi David,

Thanks for the detailed report.

I was aware of this issue but I only found out about it recently.

In Excel the top position isn't available for column charts. Instead Excel used a position called outside. Changing it to that should fix your issue.

However, this is a bug in XlsxWriter since it should throw a warning or exception when an invalid position is specified.

I'll fix it in the next release.

Thanks for reporting,

John

@jmcnamara jmcnamara self-assigned this Oct 15, 2014

@MitsuharuEishi

This comment has been minimized.

Show comment
Hide comment
@MitsuharuEishi

MitsuharuEishi Oct 15, 2014

Thank you for the quick response John. I was able to use outside_end to position my data labels.

MitsuharuEishi commented Oct 15, 2014

Thank you for the quick response John. I was able to use outside_end to position my data labels.

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Oct 29, 2014

Owner

Fixed in version 0.6.1

Thanks for the report.

Owner

jmcnamara commented Oct 29, 2014

Fixed in version 0.6.1

Thanks for the report.

@jmcnamara jmcnamara closed this Oct 29, 2014

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