Example of creating an Excel Doughnut chart.
It is possible to define chart colors for most types of libxlsxwriter charts via the series formatting functions. However, Pie/Doughnut charts are a special case since each segment is represented as a point so it is necessary to assign formatting to each point in the series.
Chart 4 shows how to set segment colors and other options.
#include "xlsxwriter.h"
}
int main() {
write_worksheet_data(worksheet, bold);
&point2,
&point3,
NULL};
}
lxw_error chart_series_set_points(lxw_chart_series *series, lxw_chart_point *points[])
Set the formatting for points in the series.
void chart_series_set_name(lxw_chart_series *series, const char *name)
Set the name of a chart series range.
void chart_set_style(lxw_chart *chart, uint8_t style_id)
Set the chart style type.
lxw_chart_series * chart_add_series(lxw_chart *chart, const char *categories, const char *values)
Add a data series to a chart.
void chart_set_hole_size(lxw_chart *chart, uint8_t size)
Set the Doughnut chart hole size.
@ LXW_CHART_DOUGHNUT
Definition: chart.h:123
void chart_title_set_name(lxw_chart *chart, const char *name)
Set the title of the chart.
void chart_set_rotation(lxw_chart *chart, uint16_t rotation)
Set the Pie/Doughnut chart rotation.
Struct to represent a chart fill.
Definition: chart.h:664
lxw_color_t color
Definition: chart.h:667
Struct to represent an Excel chart data point.
Definition: chart.h:781
lxw_chart_fill * fill
Definition: chart.h:787
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(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, lxw_chart *chart)
Insert a chart object into a worksheet.
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.