[GH-ISSUE #480] Is it possible to chart_axis_set_max to dateformat x_axis in LXW_CHART_SCATTER_STRAIGHT? #374

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

Originally created by @toge on GitHub (May 18, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/480

I'm trying to set maximum value to x_axis in LXW_CHART_SCATTER_STRAIGHT like followings.

    auto chart = workbook_add_chart(book, LXW_CHART_SCATTER_STRAIGHT);
    chart_axis_set_num_format(chart->x_axis, "MM-dd");
    chart_axis_set_num_format(chart->y_axis, "#,##0");
    chart_axis_set_max(chart->x_axis, 45900.0);
    chart_axis_set_min(chart->y_axis, 1000);

While it works fine for y_axis, there are no effect to x_axis.
I think the x-axis meets the restriction in the official documentation because it is date format.
Are there any other restrictions?

Originally created by @toge on GitHub (May 18, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/480 I'm trying to set maximum value to x_axis in LXW_CHART_SCATTER_STRAIGHT like followings. ```c++ auto chart = workbook_add_chart(book, LXW_CHART_SCATTER_STRAIGHT); chart_axis_set_num_format(chart->x_axis, "MM-dd"); chart_axis_set_num_format(chart->y_axis, "#,##0"); chart_axis_set_max(chart->x_axis, 45900.0); chart_axis_set_min(chart->y_axis, 1000); ``` While it works fine for y_axis, there are no effect to x_axis. I think the x-axis meets the restriction in the official documentation because it is date format. Are there any other restrictions?
Author
Owner

@jmcnamara commented on GitHub (May 18, 2025):

It should work as expected:

#include "xlsxwriter.h"

int main()
{
    lxw_workbook *workbook = workbook_new("gh480.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER_STRAIGHT);

    /* Add some sample data. */
    uint8_t data[5][3] = {
        {1, 2, 5},
        {2, 5, 10},
        {3, 4, 11},
        {4, 8, 12},
        {5, 7, 14}};

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

    /* Add two Chart series. */
    chart_add_series(chart,
                     "=Sheet1!$A$1:$A$5",
                     "=Sheet1!$B$1:$B$5");

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

    /* Set the axis max and mins. */
    chart_axis_set_min(chart->x_axis, 0);
    chart_axis_set_max(chart->x_axis, 6);

    chart_axis_set_min(chart->y_axis, 0);
    chart_axis_set_max(chart->y_axis, 16);

    worksheet_insert_chart(worksheet, CELL("E1"), chart);

    return workbook_close(workbook);
}

Output:

Image

<!-- gh-comment-id:2889148548 --> @jmcnamara commented on GitHub (May 18, 2025): It should work as expected: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = workbook_new("gh480.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_SCATTER_STRAIGHT); /* Add some sample data. */ uint8_t data[5][3] = { {1, 2, 5}, {2, 5, 10}, {3, 4, 11}, {4, 8, 12}, {5, 7, 14}}; 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); /* Add two Chart series. */ chart_add_series(chart, "=Sheet1!$A$1:$A$5", "=Sheet1!$B$1:$B$5"); chart_add_series(chart, "=Sheet1!$A$1:$A$5", "=Sheet1!$C$1:$C$5"); /* Set the axis max and mins. */ chart_axis_set_min(chart->x_axis, 0); chart_axis_set_max(chart->x_axis, 6); chart_axis_set_min(chart->y_axis, 0); chart_axis_set_max(chart->y_axis, 16); worksheet_insert_chart(worksheet, CELL("E1"), chart); return workbook_close(workbook); } ``` Output: ![Image](https://github.com/user-attachments/assets/0453cfb6-948a-4880-afe5-361e02462069)
Author
Owner

@toge commented on GitHub (May 19, 2025):

@jmcnamara
I'm very sorry.
It's my own bug.
libxlsxwriter works complete fine.
Thanks you for investigation.

<!-- gh-comment-id:2889393719 --> @toge commented on GitHub (May 19, 2025): @jmcnamara I'm very sorry. It's my own bug. libxlsxwriter works complete fine. Thanks you for investigation.
Author
Owner

@jmcnamara commented on GitHub (May 19, 2025):

No worries.

<!-- gh-comment-id:2889597327 --> @jmcnamara commented on GitHub (May 19, 2025): No worries.
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#374
No description provided.