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

Feature Request: Formatting for data_labels #130

Closed
technodoug opened this Issue Jun 3, 2014 · 5 comments

Comments

3 participants
@technodoug

technodoug commented Jun 3, 2014

Is it possible to add some formatting options to data_labels? Being able to set the number of decimal places would be great.

Thanks for your consideration

@technodoug technodoug closed this Jun 3, 2014

@technodoug technodoug reopened this Jun 3, 2014

@jmcnamara jmcnamara self-assigned this Jun 3, 2014

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jun 3, 2014

Owner

Hi,

I'll add this to the TODO list and see if it gets any +1s.

In the meantime Excel generally formats the data labels with the same format as the data it is linked to so you can get the same effect by formatting the input data. Like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_data_tools.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
num_format = workbook.add_format({'num_format': "0.00"})

# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Data 1', 'Data 2']
data = [
    [2, 3, 4, 5, 6, 7],
    [10, 40, 50, 20, 10, 50],
    [30, 60, 70, 50, 40, 30],
]

worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1], num_format)
worksheet.write_column('C2', data[2])

# Data Labels and Markers example.
chart = workbook.add_chart({'type': 'line'})

# Configure the first series.
chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$B$2:$B$7',
    'data_labels': {'value': 1},
    'marker': {'type': 'automatic'},
})

# Configure the second series.
chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$C$2:$C$7',
})

# Add a chart title. and some axis labels.
chart.set_title({'name': 'Chart with Data Labels and Markers'})

# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('D3', chart, {'x_offset': 25, 'y_offset': 10})

workbook.close()

Which produces a chart like the following. Note the format of the data labels:

screenshot

Owner

jmcnamara commented Jun 3, 2014

Hi,

I'll add this to the TODO list and see if it gets any +1s.

In the meantime Excel generally formats the data labels with the same format as the data it is linked to so you can get the same effect by formatting the input data. Like this:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_data_tools.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
num_format = workbook.add_format({'num_format': "0.00"})

# Add the worksheet data that the charts will refer to.
headings = ['Number', 'Data 1', 'Data 2']
data = [
    [2, 3, 4, 5, 6, 7],
    [10, 40, 50, 20, 10, 50],
    [30, 60, 70, 50, 40, 30],
]

worksheet.write_row('A1', headings, bold)
worksheet.write_column('A2', data[0])
worksheet.write_column('B2', data[1], num_format)
worksheet.write_column('C2', data[2])

# Data Labels and Markers example.
chart = workbook.add_chart({'type': 'line'})

# Configure the first series.
chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$B$2:$B$7',
    'data_labels': {'value': 1},
    'marker': {'type': 'automatic'},
})

# Configure the second series.
chart.add_series({
    'categories': '=Sheet1!$A$2:$A$7',
    'values':     '=Sheet1!$C$2:$C$7',
})

# Add a chart title. and some axis labels.
chart.set_title({'name': 'Chart with Data Labels and Markers'})

# Insert the chart into the worksheet (with an offset).
worksheet.insert_chart('D3', chart, {'x_offset': 25, 'y_offset': 10})

workbook.close()

Which produces a chart like the following. Note the format of the data labels:

screenshot

@parkermalenke

This comment has been minimized.

Show comment
Hide comment
@parkermalenke

parkermalenke Aug 20, 2014

+1 for this feature. In my use case it would be nice to format the cells separately from the values.

parkermalenke commented Aug 20, 2014

+1 for this feature. In my use case it would be nice to format the cells separately from the values.

jmcnamara added a commit that referenced this issue Oct 28, 2014

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Oct 28, 2014

Owner

I've push this feature to the master branch, along with other additions to data labels, if you would like to try it.

It works as follows:

chart.add_series({
    'values':      '=Sheet1!$A$1:$A$5',
    'data_labels': {'value': True, 'num_format': '#,##0.00'},
})
Owner

jmcnamara commented Oct 28, 2014

I've push this feature to the master branch, along with other additions to data labels, if you would like to try it.

It works as follows:

chart.add_series({
    'values':      '=Sheet1!$A$1:$A$5',
    'data_labels': {'value': True, 'num_format': '#,##0.00'},
})
@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Oct 29, 2014

Owner

Added in version 0.6.1

Thanks for the suggestion.

Owner

jmcnamara commented Oct 29, 2014

Added in version 0.6.1

Thanks for the suggestion.

@jmcnamara jmcnamara closed this Oct 29, 2014

@parkermalenke

This comment has been minimized.

Show comment
Hide comment
@parkermalenke

parkermalenke Oct 30, 2014

I'm no longer working on this project but I forwarded the update to the team who is, I think they'll find this useful.

Thanks!

parkermalenke commented Oct 30, 2014

I'm no longer working on this project but I forwarded the update to the team who is, I think they'll find this useful.

Thanks!

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