-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Chart series Fill with Type "solid" not applying custom colors
Description
Chart series with Fill{Type: "solid"} do not apply custom colors. Charts always use Excel's default theme colors instead of the specified RGB colors.
Environment
- excelize version: v2.10.0
- Go version: 1.25.7
- OS: Linux
Expected Behavior
When creating a chart with custom fill colors using Type: "solid":
Fill: excelize.Fill{Type: "solid", Color: []string{"FFCCCB"}}The chart series should display in the specified color (light red #FFCCCB).
Actual Behavior
The chart ignores the custom color and uses Excel's default theme colors (blue shades).
Minimal Reproduction
package main
import "github.com/xuri/excelize/v2"
func main() {
f := excelize.NewFile()
defer f.Close()
// Add test data
f.SetCellValue("Sheet1", "A1", "Category")
f.SetCellValue("Sheet1", "A2", 100)
varyColors := false
// Try to create red bar
f.AddChart("Sheet1", "C1", &excelize.Chart{
Type: excelize.Bar,
VaryColors: &varyColors,
Series: []excelize.ChartSeries{
{
Name: "Test",
Categories: "Sheet1!$A$1:$A$1",
Values: "Sheet1!$A$2:$A$2",
Fill: excelize.Fill{Type: "solid", Color: []string{"FFCCCB"}}, // Should be red
},
},
})
f.SaveAs("test.xlsx")
}Result: Bar appears in default blue instead of red.
Root Cause
File: drawing.go, function drawShapeFill() (line ~840)
The function only processes Fill colors when Type == "pattern" && Pattern == 1:
func (f *File) drawShapeFill(fill Fill, spPr *cSpPr) *cSpPr {
if fill.Type == "pattern" && fill.Pattern == 1 { // <-- Only checks pattern
// Apply custom color
}
return spPr
}This means Type: "solid" is completely ignored.
Workaround
Use Type: "pattern" with Pattern: 1 instead:
Fill: excelize.Fill{Type: "pattern", Pattern: 1, Color: []string{"FFCCCB"}}Proposed Fix
Change the condition to also accept Type: "solid":
if fill.Type == "solid" || (fill.Type == "pattern" && fill.Pattern == 1) {Impact
- Affected: All chart types (bar, line, pie, scatter, etc.)
- Also affects: DataPoint colors, markers, plot area fills, up/down bars
- Severity: Medium - workaround exists but not intuitive
- Breaking change: None - only adds support for previously ignored syntax
Pull Request
I have a fix ready with tests. Branch: fix/chart-fill-solid-type #2260
Tested with:
- ✅ Bar charts with 5 custom colored series
- ✅ Pie charts with DataPoint colors
- ✅ All colors render correctly