2016-05-23 00:22:26 +01:00
|
|
|
/*
|
|
|
|
* An example showing all 48 default chart styles available in Excel 2007
|
|
|
|
* using the libxlsxwriter library. Note, these styles are not the same as the
|
|
|
|
* styles available in Excel 2013.
|
|
|
|
*
|
2025-02-11 00:03:36 +00:00
|
|
|
* Copyright 2014-2025, John McNamara, jmcnamara@cpan.org
|
2016-05-23 00:22:26 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "xlsxwriter.h"
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
int chart_types[] = {LXW_CHART_COLUMN, LXW_CHART_AREA, LXW_CHART_LINE, LXW_CHART_PIE};
|
2023-09-24 20:40:07 +01:00
|
|
|
const char *chart_names[] = {"Column", "Area", "Line", "Pie"};
|
2016-05-23 00:22:26 +01:00
|
|
|
char chart_title[32] = {0};
|
|
|
|
int row_num, col_num, chart_num, style_num;
|
|
|
|
lxw_worksheet *worksheet;
|
|
|
|
lxw_chart *chart;
|
|
|
|
|
2019-11-16 20:32:37 +00:00
|
|
|
lxw_workbook *workbook = workbook_new("chart_styles.xlsx");
|
2016-05-23 00:22:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
for (chart_num = 0; chart_num < 4; chart_num++) {
|
|
|
|
|
|
|
|
/* Add a worksheet for each chart type. */
|
|
|
|
worksheet = workbook_add_worksheet(workbook, chart_names[chart_num]);
|
|
|
|
worksheet_set_zoom(worksheet, 30);
|
|
|
|
|
|
|
|
|
|
|
|
/* Create 48 charts, each with a different style. */
|
|
|
|
style_num = 1;
|
|
|
|
for (row_num = 0; row_num < 90; row_num += 15) {
|
|
|
|
|
|
|
|
for (col_num = 0; col_num < 64; col_num += 8) {
|
|
|
|
|
|
|
|
chart = workbook_add_chart(workbook, chart_types[chart_num]);
|
2022-02-23 23:17:54 +00:00
|
|
|
snprintf(chart_title, 32, "Style %d", style_num);
|
2016-05-23 00:22:26 +01:00
|
|
|
|
|
|
|
chart_add_series(chart, NULL, "=Data!$A$1:$A$6");
|
|
|
|
chart_title_set_name(chart, chart_title);
|
|
|
|
chart_set_style(chart, style_num);
|
|
|
|
|
|
|
|
worksheet_insert_chart(worksheet, row_num, col_num, chart);
|
|
|
|
|
|
|
|
style_num++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a worksheet with data for the charts. */
|
|
|
|
worksheet = workbook_add_worksheet(workbook, "Data");
|
|
|
|
worksheet_write_number(worksheet, 0, 0, 10, NULL);
|
|
|
|
worksheet_write_number(worksheet, 1, 0, 40, NULL);
|
|
|
|
worksheet_write_number(worksheet, 2, 0, 50, NULL);
|
|
|
|
worksheet_write_number(worksheet, 3, 0, 20, NULL);
|
|
|
|
worksheet_write_number(worksheet, 4, 0, 10, NULL);
|
|
|
|
worksheet_write_number(worksheet, 5, 0, 50, NULL);
|
|
|
|
|
|
|
|
return workbook_close(workbook);
|
|
|
|
}
|