[GH-ISSUE #477] Add plot_area layout customization (like in Python's xlsxwriter) #370

Closed
opened 2026-05-05 12:13:02 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @dapeipa on GitHub (Mar 26, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/477

Originally assigned to: @jmcnamara on GitHub.

Description:
I would like to request the addition of functionality to customize the plot_area size and position in charts, similar to what is available in Python's xlsxwriter library. Currently, Python allows configuring the plot_area with precise layout parameters like this:

chart.set_plotarea({
    'layout': {
        'x':      0.13,
        'y':      0.26,
        'width':  0.73,
        'height': 0.57,
    }
})

However, this feature does not seem to be exposed in libxlsxwriter's C API.

Use Case:
Being able to adjust the plot_area dimensions is useful for:

  • Fine-tuning chart aesthetics.
  • Avoiding overlaps with titles/legends.
  • Ensuring consistency across multiple charts.

Proposed Solution:
Add a function like:

void chart_plotarea_set_layout()

Originally created by @dapeipa on GitHub (Mar 26, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/477 Originally assigned to: @jmcnamara on GitHub. **Description:** I would like to request the addition of functionality to customize the plot_area size and position in charts, similar to what is available in Python's xlsxwriter library. Currently, Python allows configuring the plot_area with precise layout parameters like this: ``` chart.set_plotarea({ 'layout': { 'x': 0.13, 'y': 0.26, 'width': 0.73, 'height': 0.57, } }) ``` However, this feature does not seem to be exposed in libxlsxwriter's C API. **Use Case:** Being able to adjust the plot_area dimensions is useful for: - Fine-tuning chart aesthetics. - Avoiding overlaps with titles/legends. - Ensuring consistency across multiple charts. **Proposed Solution:** Add a function like: ` void chart_plotarea_set_layout() `
gitea-mirror 2026-05-05 12:13:02 -06:00
Author
Owner

@jmcnamara commented on GitHub (Mar 26, 2025):

Thanks for the suggestion. I will look into it in the shorter term.

<!-- gh-comment-id:2755714445 --> @jmcnamara commented on GitHub (Mar 26, 2025): Thanks for the suggestion. I will look into it in the shorter term.
Author
Owner

@jmcnamara commented on GitHub (Mar 28, 2025):

I've pushed an initial WIP version of this to main. It still needs some tests (mainly around chart title positing) and documentation but it is functional. You can now do something like this:


#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = workbook_new("chart_layout.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

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

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    /* Set the plotarea layout. */
    lxw_chart_layout layout = {
        .x = 0.13,
        .y = 0.26,
        .width = 0.75,
        .height = 0.60,
    };

    chart_plotarea_set_layout(chart, &layout);

    worksheet_insert_chart(worksheet, 0, 4, chart);

    return workbook_close(workbook);
}

Which give output like this:

Image

If you get a chance to try it let me know. I'll finish it off over the next few days.

<!-- gh-comment-id:2759890082 --> @jmcnamara commented on GitHub (Mar 28, 2025): I've pushed an initial WIP version of this to main. It still needs some tests (mainly around chart title positing) and documentation but it is functional. You can now do something like this: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("chart_layout.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN); uint8_t data[5][3] = { {1, 2, 3}, {2, 4, 6}, {3, 6, 9}, {4, 8, 12}, {5, 10, 15} }; int row, col; for (row = 0; row < 5; row++) for (col = 0; col < 3; col++) worksheet_write_number(worksheet, row, col, data[row][col], NULL); chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5"); chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5"); chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5"); /* Set the plotarea layout. */ lxw_chart_layout layout = { .x = 0.13, .y = 0.26, .width = 0.75, .height = 0.60, }; chart_plotarea_set_layout(chart, &layout); worksheet_insert_chart(worksheet, 0, 4, chart); return workbook_close(workbook); } ``` Which give output like this: ![Image](https://github.com/user-attachments/assets/eb019131-22a3-4ac6-bb53-2d23b22eef77) If you get a chance to try it let me know. I'll finish it off over the next few days.
Author
Owner

@dapeipa commented on GitHub (Mar 28, 2025):

Thank you for the prompt fix! I tested the changes in my specific scenario (a chart without a title ) on Linux with LibreOffice Community Version 25.2.1.2 (X86_64) , and it works flawlessly.

<!-- gh-comment-id:2761932150 --> @dapeipa commented on GitHub (Mar 28, 2025): Thank you for the prompt fix! I tested the changes in my specific scenario (a chart without a title ) on Linux with LibreOffice Community Version 25.2.1.2 (X86_64) , and it works flawlessly.
Author
Owner

@jmcnamara commented on GitHub (Mar 29, 2025):

This is upstream now in v1.2.1. Thanks for the prompt.

Closing.

<!-- gh-comment-id:2763264082 --> @jmcnamara commented on GitHub (Mar 29, 2025): This is upstream now in v1.2.1. Thanks for the prompt. Closing.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#370
No description provided.