A demo of an various Excel chart data label features that are available via a libxlsxwriter chart, including custom data labels.
Chart 1: chart with standard data labels.
Chart 2: chart with Category and Value data labels.
Chart 3: chart with data labels with a user defined font.
Chart 4: chart with data labels and formatting.
Chart 5: chart with custom string data labels.
Chart 6: chart with custom data labels referenced from worksheet cells.
Chart 7: chart with a mix of custom and default labels. The items initialized with '{0}' and items without a custom label (points 5 and 6 which come after NULL) will get the default value. We also set a font for the custom items as an extra example.
Chart 8: chart with some deleted custom labels and defaults.
Chart 9: chart with custom string data labels and formatting.
#include "xlsxwriter.h"
int main() {
"=Sheet1!$B$2:$B$7");
"=Sheet1!$B$2:$B$7");
"=Sheet1!$B$2:$B$7");
"=Sheet1!$B$2:$B$7");
"=Sheet1!$B$2:$B$7");
&data_label5_1,
&data_label5_2,
&data_label5_3,
&data_label5_4,
&data_label5_5,
&data_label5_6,
NULL
};
"=Sheet1!$B$2:$B$7");
&data_label6_1,
&data_label6_2,
&data_label6_3,
&data_label6_4,
&data_label6_5,
&data_label6_6,
NULL
};
"=Sheet1!$B$2:$B$7");
&data_label7_1,
&data_label7_2,
&data_label7_3,
&data_label7_4,
NULL
};
"=Sheet1!$B$2:$B$7");
&hide,
&keep,
&hide,
&hide,
&keep,
&hide,
NULL
};
"=Sheet1!$B$2:$B$7");
&data_label9_1,
&data_label9_2,
&data_label9_3,
&data_label9_4,
&data_label9_5,
&data_label9_6,
NULL
};
}
void chart_series_set_labels_line(lxw_chart_series *series, lxw_chart_line *line)
Set the line properties for the data labels in a chart series.
lxw_chart_series * chart_add_series(lxw_chart *chart, const char *categories, const char *values)
Add a data series to a chart.
@ LXW_CHART_COLUMN
Definition: chart.h:114
void chart_title_set_name(lxw_chart *chart, const char *name)
Set the title of the chart.
@ LXW_CHART_LEGEND_NONE
Definition: chart.h:168
void chart_series_set_labels(lxw_chart_series *series)
Add data labels to a chart series.
lxw_error chart_series_set_labels_custom(lxw_chart_series *series, lxw_chart_data_label *data_labels[])
Set the properties for data labels in a series.
void chart_series_set_labels_fill(lxw_chart_series *series, lxw_chart_fill *fill)
Set the fill properties for the data labels in a chart series.
void chart_series_set_labels_font(lxw_chart_series *series, lxw_chart_font *font)
Set the font properties for chart data labels in a series.
void chart_series_set_labels_options(lxw_chart_series *series, uint8_t show_name, uint8_t show_category, uint8_t show_value)
Set the display options for the labels of a data series.
void chart_legend_set_position(lxw_chart *chart, uint8_t position)
Set the position of the chart legend.
@ LXW_TRUE
Definition: common.h:54
@ LXW_FALSE
Definition: common.h:52
Struct to represent an Excel chart data label.
Definition: chart.h:800
uint8_t hide
Definition: chart.h:808
const char * value
Definition: chart.h:804
Struct to represent a chart fill.
Definition: chart.h:664
lxw_color_t color
Definition: chart.h:667
Struct to represent a chart font.
Definition: chart.h:700
lxw_color_t color
Definition: chart.h:727
uint8_t bold
Definition: chart.h:709
Struct to represent a chart line.
Definition: chart.h:640
lxw_color_t color
Definition: chart.h:643
Options for inserted charts.
Definition: worksheet.h:1753
int32_t x_offset
Definition: worksheet.h:1756
Struct to represent an Excel chart data series.
Definition: chart.h:961
Struct to represent an Excel chart.
Definition: chart.h:1091
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2115
#define CELL(cell)
Convert an Excel A1 cell string into a (row, col) pair.
Definition: utility.h:46
lxw_chart * workbook_add_chart(lxw_workbook *workbook, uint8_t chart_type)
Create a new chart to be added to a worksheet:
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_insert_chart_opt(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, lxw_chart *chart, lxw_chart_options *user_options)
Insert a chart object into a worksheet, with options.
lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)
Write a string to a worksheet cell.
lxw_error worksheet_write_number(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, double number, lxw_format *format)
Write a number to a worksheet cell.