I am having trouble to add custom colors in pie chart slices. I am using go chart library and not sure how to add custom colors in my chart dynamically.
Here I am working on a graph using this code, I know we have a chart style option to assign colors using drawing.Color{R,G,B,A}
but that will specific only one color for all the slices. I want to have my own custom color specified for each pie chart slice dynamically
raw := `{"reaction_summary": {"ANGRY": 7,"HAHA": 40,"LIKE": 161,"LOVE": 56,"SAD": 26,"SHOCK": 6}}`
// Parse JSON
data := struct {
ReactionSummary map[string]int `json:"reaction_summary"`
}{}
if err := json.Unmarshal([]byte(raw), &data); err != nil {
log.Fatal(err)
}
// Populate a slice of chart values
var values []chart.Value
for l, v := range data.ReactionSummary {
values = append(values, chart.Value{Label: l, Value: float64(v)})
}
// Initialize the chart
pie := chart.PieChart{
Width: 512,
Height: 512,
Values: values,
}