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: Add trendline equation display #357

Closed
NotSqrt opened this Issue Jun 3, 2016 · 4 comments

Comments

2 participants
@NotSqrt

NotSqrt commented Jun 3, 2016

Hi,

Add support for dispEq : display the equation of a trendline. This could be a useful option.

The xml looks like:

<c:trendline>
    <c:trendlineType val="linear"/>
    <c:dispEq val="1"/>
    <c:trendlineLbl>
            <c:layout/>
            <c:numFmt formatCode="General" sourceLinked="0"/>
    </c:trendlineLbl>
</c:trendline>

Thanks !

@jmcnamara jmcnamara changed the title from Add support for dispEq : display the equation of a trendline to Feature request: Add trendline equation display Jun 3, 2016

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jun 3, 2016

Owner

Hi,

I plan to do some other work around trendlines in the next few months. I'll look into adding this at the same time.

John

Owner

jmcnamara commented Jun 3, 2016

Hi,

I plan to do some other work around trendlines in the next few months. I'll look into adding this at the same time.

John

@jmcnamara jmcnamara self-assigned this Jun 3, 2016

jmcnamara added a commit that referenced this issue Jun 4, 2016

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara Jun 4, 2016

Owner

There is an initial version of this feature on the master branch that you can try out. Add 'display_equation': True to the trendline properties.

Documentation to follow but here is an example:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_equation.xlsx')

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'line'})


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',
    'trendline': {
        'type': 'polynomial',
        'name': 'My trend name',
        'order': 2,
        'forward': 0.5,
        'backward': 0.5,
        'display_equation': True,
        'line': {
            'color': 'red',
            'width': 1,
            'dash_type': 'long_dash',
        },
    },
})

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

worksheet.insert_chart('E9', chart)

workbook.close()

screenshot

Owner

jmcnamara commented Jun 4, 2016

There is an initial version of this feature on the master branch that you can try out. Add 'display_equation': True to the trendline properties.

Documentation to follow but here is an example:

import xlsxwriter

workbook = xlsxwriter.Workbook('chart_equation.xlsx')

worksheet = workbook.add_worksheet()
chart = workbook.add_chart({'type': 'line'})


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',
    'trendline': {
        'type': 'polynomial',
        'name': 'My trend name',
        'order': 2,
        'forward': 0.5,
        'backward': 0.5,
        'display_equation': True,
        'line': {
            'color': 'red',
            'width': 1,
            'dash_type': 'long_dash',
        },
    },
})

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

worksheet.insert_chart('E9', chart)

workbook.close()

screenshot

@NotSqrt

This comment has been minimized.

Show comment
Hide comment
@NotSqrt

NotSqrt Jun 6, 2016

Works for me !

NotSqrt commented Jun 6, 2016

Works for me !

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara
Owner

jmcnamara commented Jun 7, 2016

Added in version 0.9.0: https://xlsxwriter.readthedocs.io/changes.html

Thanks.

@jmcnamara jmcnamara closed this Jun 7, 2016

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