gitee.com/lh-her-team/common@v1.5.1/report/report.go (about) 1 package report 2 3 import ( 4 "os" 5 "strings" 6 7 "github.com/go-echarts/go-echarts/v2/charts" 8 "github.com/go-echarts/go-echarts/v2/opts" 9 ) 10 11 // Report Used to generate charts, This method can be used to produce beautiful diagrams for stress testing 12 func Report(title, subtitle string, xAxis interface{}, series ...Series) { 13 // create a new bar instance 14 bar := charts.NewBar() 15 // set some global options like Title/Legend/ToolTip or anything else 16 bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{ 17 Title: title, 18 Subtitle: subtitle, 19 })) 20 // Put data into instance 21 //bar.SetXAxis([]string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"}). 22 // AddSeries("Category A", generateBarItems()). 23 // AddSeries("Category B", generateBarItems()) 24 axis := bar.SetXAxis(xAxis) 25 for i := range series { 26 axis.AddSeries(series[i].Name, series[i].Data, series[i].Options...) 27 } 28 title = strings.ToLower(title) 29 title = strings.Replace(title, " ", "_", -1) 30 // Where the magic happens 31 f, _ := os.Create(title + ".html") 32 _ = bar.Render(f) 33 } 34 35 type Series struct { 36 Name string 37 Data []opts.BarData 38 Options []charts.SeriesOpts 39 }