vicanso / go-charts

A charts library for Golang
MIT License
229 stars 34 forks source link

Change pie chart color #92

Open hypolas opened 2 weeks ago

hypolas commented 2 weeks ago

Hello,

I try to set color to pie chart serie.

In my case, I need, for exemple, to set color "red" (for error data) and green (for valide data) .

That seems don't work.  I try with:

    p, err := charts.PieRender(
        values,
        charts.TitleOptionFunc(charts.TitleOption{
            Text:    "Rainfall vs Evaporation",
            Subtext: "Fake Data",
            Left:    charts.PositionCenter,
        }),
        charts.PaddingOptionFunc(charts.Box{
            Top:    20,
            Right:  20,
            Bottom: 10,
            Left:   20,
        }),
        charts.LegendOptionFunc(charts.LegendOption{
            Orient: charts.OrientVertical,
            Data: []string{
                "tests",
                "failures",
                "errors",
            },
            Left: charts.PositionLeft,
        }),
        charts.PieSeriesShowLabel(),
        func(opt *charts.ChartOption) {
            opt.SeriesList[1].Style.FillColor = drawing.ColorRed
            opt.SeriesList[2].Style.FillColor = drawing.ColorRed
        },
    )
vicanso commented 2 weeks ago

I'll fix it later.

vicanso commented 2 weeks ago

This can be temporarily solved by specifying a theme color, https://github.com/vicanso/go-charts/blob/main/theme.go#L124