package main import ( "os" "path/filepath" "git.smarteching.com/zeni/go-charts/v2" ) func writeFile(buf []byte) error { tmpPath := "./tmp" err := os.MkdirAll(tmpPath, 0700) if err != nil { return err } file := filepath.Join(tmpPath, "pie-chart.png") err = os.WriteFile(file, buf, 0600) if err != nil { return err } return nil } func main() { values := []float64{ 1048, 735, 580, 484, 300, } 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: 20, Left: 20, }), charts.LegendOptionFunc(charts.LegendOption{ Orient: charts.OrientVertical, Data: []string{ "Search Engine", "Direct", "Email", "Union Ads", "Video Ads", }, Left: charts.PositionLeft, }), charts.PieSeriesShowLabel(), ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } err = writeFile(buf) if err != nil { panic(err) } }