[GH-ISSUE #504] Feature Request: Gradient Fills for Charts #391

Open
opened 2026-05-05 12:14:33 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @kruftindustries on GitHub (Jan 12, 2026).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/504

Originally assigned to: @jmcnamara on GitHub.

Support for gradient fills on chart series and plot areas, allowing smooth color transitions for enhanced visual presentation.

API Changes:

New enum in chart.h:
typedef enum lxw_chart_gradient_fill_type {
LXW_CHART_GRADIENT_FILL_LINEAR, /* Linear gradient */
LXW_CHART_GRADIENT_FILL_RADIAL, /* Radial gradient */
LXW_CHART_GRADIENT_FILL_RECTANGULAR, /* Rectangular gradient */
LXW_CHART_GRADIENT_FILL_PATH /* Path gradient */
} lxw_chart_gradient_fill_type;

New struct in chart.h:
typedef struct lxw_chart_gradient_fill {
lxw_chart_gradient_fill_type type; /* Gradient type */
lxw_color_t colors[LXW_CHART_GRADIENT_FILL_MAX_STOPS]; /* Color array */
uint8_t positions[LXW_CHART_GRADIENT_FILL_MAX_STOPS]; /* Stop positions (0-100) */
uint8_t num_stops; /* Number of stops (2-10) */
double angle; /* Angle for linear gradients (0-359) */
} lxw_chart_gradient_fill;

New functions:
void chart_series_set_gradient(lxw_chart_series *series, lxw_chart_gradient_fill *gradient);
void chart_chartarea_set_gradient(lxw_chart *chart, lxw_chart_gradient_fill *gradient);
void chart_plotarea_set_gradient(lxw_chart *chart, lxw_chart_gradient_fill *gradient);

Code Example:
#include "xlsxwriter.h"

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

lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5", 0);

/* Apply gradient fill: dark to light */
lxw_chart_gradient_fill gradient = {
.type = LXW_CHART_GRADIENT_FILL_LINEAR,
.colors = {0x963735, 0xF1DCDB},
.num_stops = 2,
};
chart_series_set_gradient(series, &gradient);

worksheet_insert_chart(worksheet, CELL("C2"), chart);
return workbook_close(workbook);
}

Image
Originally created by @kruftindustries on GitHub (Jan 12, 2026). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/504 Originally assigned to: @jmcnamara on GitHub. ### Support for gradient fills on chart series and plot areas, allowing smooth color transitions for enhanced visual presentation. API Changes: New enum in chart.h: `typedef enum lxw_chart_gradient_fill_type {` ` LXW_CHART_GRADIENT_FILL_LINEAR, /* Linear gradient */` ` LXW_CHART_GRADIENT_FILL_RADIAL, /* Radial gradient */` ` LXW_CHART_GRADIENT_FILL_RECTANGULAR, /* Rectangular gradient */` ` LXW_CHART_GRADIENT_FILL_PATH /* Path gradient */` `} lxw_chart_gradient_fill_type;` New struct in chart.h: `typedef struct lxw_chart_gradient_fill {` ` lxw_chart_gradient_fill_type type; /* Gradient type */` ` lxw_color_t colors[LXW_CHART_GRADIENT_FILL_MAX_STOPS]; /* Color array */` ` uint8_t positions[LXW_CHART_GRADIENT_FILL_MAX_STOPS]; /* Stop positions (0-100) */` ` uint8_t num_stops; /* Number of stops (2-10) */` ` double angle; /* Angle for linear gradients (0-359) */` `} lxw_chart_gradient_fill;` New functions: `void chart_series_set_gradient(lxw_chart_series *series, lxw_chart_gradient_fill *gradient);` `void chart_chartarea_set_gradient(lxw_chart *chart, lxw_chart_gradient_fill *gradient);` `void chart_plotarea_set_gradient(lxw_chart *chart, lxw_chart_gradient_fill *gradient);` Code Example: `#include "xlsxwriter.h"` `int main() {` ` lxw_workbook *workbook = workbook_new("gradient.xlsx");` ` lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);` ` lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_COLUMN);` ` lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5", 0);` ` /* Apply gradient fill: dark to light */` ` lxw_chart_gradient_fill gradient = {` ` .type = LXW_CHART_GRADIENT_FILL_LINEAR,` ` .colors = {0x963735, 0xF1DCDB},` ` .num_stops = 2,` ` };` ` chart_series_set_gradient(series, &gradient);` ` worksheet_insert_chart(worksheet, CELL("C2"), chart);` ` return workbook_close(workbook);` `}` <img width="480" height="288" alt="Image" src="https://github.com/user-attachments/assets/1e7aec9e-0c1d-4849-bd48-7191637b6f4f" />
gitea-mirror added the
feature request
medium term
labels 2026-05-05 12:14:33 -06:00
Author
Owner

@jmcnamara commented on GitHub (Jan 12, 2026):

This one is useful and slightly higher priority but the requires a good bit of API additions. I would say this is medium to long term.

<!-- gh-comment-id:3737765651 --> @jmcnamara commented on GitHub (Jan 12, 2026): This one is useful and slightly higher priority but the requires a good bit of API additions. I would say this is medium to long term.
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#391
No description provided.