[GH-ISSUE #199] Bug: Bold Chart Title and Legend #160

Closed
opened 2026-05-05 11:48:59 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @ungakatunga on GitHub (Oct 8, 2018).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/199

Originally assigned to: @jmcnamara on GitHub.

The bold attribute of the font has no effect on the chart title and chart legend. Title and legend is always bold, there is currently no way to reset this.

Originally created by @ungakatunga on GitHub (Oct 8, 2018). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/199 Originally assigned to: @jmcnamara on GitHub. The bold attribute of the font has no effect on the chart title and chart legend. Title and legend is always bold, there is currently no way to reset this.
gitea-mirror 2026-05-05 11:48:59 -06:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@jmcnamara commented on GitHub (Oct 8, 2018):

Can you add a small, complete, working program that demonstrates the issue.

Thanks,

John

<!-- gh-comment-id:427763081 --> @jmcnamara commented on GitHub (Oct 8, 2018): Can you add a small, complete, working program that demonstrates the issue. Thanks, John
Author
Owner

@jmcnamara commented on GitHub (Oct 8, 2018):

I created a test case for this. The Excel default is to make the title bold if no format is specified. However, you can turn it off as shown below:

#include "xlsxwriter.h"

int main() {

    lxw_workbook  *workbook  = new_workbook("chart_title_font.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart1    = workbook_add_chart(workbook, LXW_CHART_BAR);
    lxw_chart     *chart2    = workbook_add_chart(workbook, LXW_CHART_BAR);

    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(chart1, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart1, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart1, NULL, "=Sheet1!$C$1:$C$5");

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

    chart_title_set_name(chart1, "Title");
    chart_title_set_name(chart2, "Title");

    lxw_chart_font font1 = {.bold = LXW_FALSE};
    chart_title_set_name_font(chart2, &font1);

    worksheet_insert_chart(worksheet, CELL("E1"),  chart1);
    worksheet_insert_chart(worksheet, CELL("E16"), chart2);

    return workbook_close(workbook);
}

Output. The first chart is the default (title is bold) and the second has it turned off.

aa_image

<!-- gh-comment-id:427786295 --> @jmcnamara commented on GitHub (Oct 8, 2018): I created a test case for this. The Excel default is to make the title bold if no format is specified. However, you can turn it off as shown below: ```C #include "xlsxwriter.h" int main() { lxw_workbook *workbook = new_workbook("chart_title_font.xlsx"); lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL); lxw_chart *chart1 = workbook_add_chart(workbook, LXW_CHART_BAR); lxw_chart *chart2 = workbook_add_chart(workbook, LXW_CHART_BAR); 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(chart1, NULL, "=Sheet1!$A$1:$A$5"); chart_add_series(chart1, NULL, "=Sheet1!$B$1:$B$5"); chart_add_series(chart1, NULL, "=Sheet1!$C$1:$C$5"); chart_add_series(chart2, NULL, "=Sheet1!$A$1:$A$5"); chart_add_series(chart2, NULL, "=Sheet1!$B$1:$B$5"); chart_add_series(chart2, NULL, "=Sheet1!$C$1:$C$5"); chart_title_set_name(chart1, "Title"); chart_title_set_name(chart2, "Title"); lxw_chart_font font1 = {.bold = LXW_FALSE}; chart_title_set_name_font(chart2, &font1); worksheet_insert_chart(worksheet, CELL("E1"), chart1); worksheet_insert_chart(worksheet, CELL("E16"), chart2); return workbook_close(workbook); } ``` Output. The first chart is the default (title is bold) and the second has it turned off. ![aa_image](https://user-images.githubusercontent.com/94267/46604195-5a8c3c80-caed-11e8-9c56-b8887ca7f16c.png)
Author
Owner

@jmcnamara commented on GitHub (Oct 8, 2018):

So, this doesn't look like an issue to me and I'll close it if you have don't have any other follow-up.

<!-- gh-comment-id:427786535 --> @jmcnamara commented on GitHub (Oct 8, 2018): So, this doesn't look like an issue to me and I'll close it if you have don't have any other follow-up.
Author
Owner

@ungakatunga commented on GitHub (Oct 8, 2018):

hmm...

the only differences in my code to yours are:

lxw_chart_font font_20  = { "Calibri Light", 20., 0, 0, 0, 0, 0x595959, 0, 0, 0, 1 };
// to make sure the font is properly initialized

lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN_STACKED); 
chart_set_style(chart, 11);

...
// add data & setup
...

chart_title_set_name_font(chart, &font_20);

chartsheet_set_chart(chartsheet, chart);

In my generated xlsx the title is bold. Also in a second version, without the special chart style.

<!-- gh-comment-id:427805721 --> @ungakatunga commented on GitHub (Oct 8, 2018): hmm... the only differences in my code to yours are: ``` lxw_chart_font font_20 = { "Calibri Light", 20., 0, 0, 0, 0, 0x595959, 0, 0, 0, 1 }; // to make sure the font is properly initialized lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN_STACKED); chart_set_style(chart, 11); ... // add data & setup ... chart_title_set_name_font(chart, &font_20); chartsheet_set_chart(chartsheet, chart); ``` In my generated xlsx the title is bold. Also in a second version, without the special chart style.
Author
Owner

@RaFaeL-NN commented on GitHub (Oct 8, 2018):

It's same with https://github.com/jmcnamara/libxlsxwriter/issues/146
Try to set bold property to 2 instead of 0. It helps me

<!-- gh-comment-id:427831208 --> @RaFaeL-NN commented on GitHub (Oct 8, 2018): It's same with https://github.com/jmcnamara/libxlsxwriter/issues/146 Try to set bold property to 2 instead of 0. It helps me
Author
Owner

@jmcnamara commented on GitHub (Oct 8, 2018):

I found the issue. It is a bug.

You can use the workaround suggested by @RaFaeL-NN and set bold to an even non-zero number, like 2.

<!-- gh-comment-id:427844496 --> @jmcnamara commented on GitHub (Oct 8, 2018): I found the issue. It is a bug. You can use the workaround suggested by @RaFaeL-NN and set bold to an even non-zero number, like 2.
Author
Owner

@ungakatunga commented on GitHub (Oct 8, 2018):

Ok, thank you two.

<!-- gh-comment-id:427846427 --> @ungakatunga commented on GitHub (Oct 8, 2018): Ok, thank you two.
Author
Owner

@jmcnamara commented on GitHub (Jul 12, 2021):

I've pushed a fix for this to main. From the updated docs:

In Excel a chart title font is bold by default (as shown in the image above). To turn off bold in the font you cannot use LXW_FALSE (0) since that is indistinguishable from an uninitialized value. Instead you should use LXW_EXPLICIT_FALSE:

lxw_chart_font font = {.bold = LXW_EXPLICIT_FALSE, .color = LXW_COLOR_BLUE};
 
chart_title_set_name(chart, "Year End Results");
chart_title_set_name_font(chart, &font);

LXW_EXPLICIT_FALSE has a value of 2, as suggested by @RaFaeL-NN.

<!-- gh-comment-id:878630212 --> @jmcnamara commented on GitHub (Jul 12, 2021): I've pushed a fix for this to main. From the updated docs: > In Excel a chart title font is bold by default (as shown in the image above). To turn off bold in the font you cannot use `LXW_FALSE` (0) since that is indistinguishable from an uninitialized value. Instead you should use `LXW_EXPLICIT_FALSE`: ```C lxw_chart_font font = {.bold = LXW_EXPLICIT_FALSE, .color = LXW_COLOR_BLUE}; chart_title_set_name(chart, "Year End Results"); chart_title_set_name_font(chart, &font); ``` LXW_EXPLICIT_FALSE has a value of 2, as suggested by @RaFaeL-NN.
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#160
No description provided.