qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
17.62k stars 1.68k forks source link

How can I set the `Fill` color for pie chart ? #1904

Closed Kerlli closed 1 month ago

Kerlli commented 1 month ago

Description

Hi, Maintainers

How can I set the Fill color for each part of pie chart ?

Like:

for idx, row := range [][]interface{}{
        {"Apple", "Orange", "Pear"},
        {2, 3, 3},
    } {
        cell, err := excelize.CoordinatesToCellName(1, idx+1)
        if err != nil {
            fmt.Println(err)
            return
        }
        if err := f.SetSheetRow("Sheet1", cell, &row); err != nil {
            fmt.Println(err)
            return
        }
    }

if err := f.AddChart("Sheet1", "E1", &excelize.Chart{
        Type: excelize.Pie,
        Series: []excelize.ChartSeries{
            {
                Name:       "Amount",
                Categories: "Sheet1!$A$1:$C$1",
                Values:     "Sheet1!$A$2:$C$2",
            },
        },
        Title: []excelize.RichTextRun{
            {
                Text: "Fruit Pie Chart",
            },
        },
    }); err != nil {
        fmt.Println(err)
        return
    }

I'm wondering about how to set colors for Apple, Orange and Pear

Thanks.

Steps to reproduce the issue:

Describe the results you received:

Each series fill color can only be set by:

excelize.ChartSeries{
    Fill: excelize.Fill{
        Type:    "pattern",
        Color:   []string{"#505050"},
        Pattern: 1,
    },
}

Describe the results you expected:

Output of go version:

v1.22

Excelize version or commit ID:

2.8.1

Environment details (OS, Microsoft Excel™ version, physical, etc.):

xuri commented 1 month ago

Duplicated with #1862.

xuri commented 1 month ago

I closed this issue, and keep #1862 to track this feature request, if you have any questions, please let me know to reopen this anytime.