package main import ( "bytes" "context" "fmt" "log" "os" "os/signal" "github.com/go-echarts/go-echarts/v2/charts" "github.com/go-echarts/go-echarts/v2/opts" ) func main() { ctx, can := signal.NotifyContext(context.Background()) defer can() if err := run(ctx); err != nil { panic(err) } } func run(ctx context.Context) error { config, err := newConfig() if err != nil { return err } log.Printf("%+v", config) x, y, data, err := config.Data.AsScatterData() if err != nil { return err } log.Printf("(%s, %s) = %v", x, y, data) scatter := charts.NewScatter() scatter.SetGlobalOptions(charts.WithTitleOpts(opts.Title{ Title: config.Data.Title, Subtitle: config.Data.Subtitle, })) scatter.SetGlobalOptions(charts.WithLegendOpts(opts.Legend{Show: false})) scatter.SetGlobalOptions(charts.WithXAxisOpts(opts.XAxis{ Name: x, NameLocation: "middle", NameGap: config.Data.Weight.Floor + config.Data.Weight.Range, })) scatter.SetGlobalOptions(charts.WithYAxisOpts(opts.YAxis{ Name: y, NameLocation: "middle", NameGap: config.Data.Weight.Floor + config.Data.Weight.Range, })) scatter.AddSeries(y, data) buff := bytes.NewBuffer(nil) if err := scatter.Render(buff); err != nil { return err } switch config.Output.Scheme { case "file": return os.WriteFile(config.Output.Path, buff.Bytes(), os.ModePerm) } return fmt.Errorf("not impl output scheme: %s", config.Output.Scheme) }