package goCharts /* * @author: sre @date: 2022/9/17 0017 @desc: todo * */ import ( "github.com/vicanso/go-charts/v2" "math/rand" "time" ) func getRand(len int) []float64 { var res []float64 for i := 0; i < len; i++ { randFloat := float64(rand.Intn(1000)) res = append(res, randFloat) } return res } func Draw() { values := [][]float64{ getRand(30), getRand(30), getRand(30), getRand(30), } p, err := charts.LineRender( values, //charts.SVGTypeOption(), charts.ThemeOptionFunc(charts.ThemeGrafana), charts.WidthOptionFunc(720), charts.HeightOptionFunc(1280), charts.TitleTextOptionFunc("symbol price"), charts.XAxisDataOptionFunc(getLastDays(30)), charts.LegendLabelsOptionFunc([]string{ "BTC", "ETH", "BNB", "TRX", }, "150"), func(opt *charts.ChartOption) { opt.Legend.Padding = charts.Box{ Top: 5, Bottom: 10, } opt.SymbolShow = charts.FalseFlag() opt.LineStrokeWidth = 1 }, ) if err != nil { panic(err) } buf, err := p.Bytes() if err != nil { panic(err) } err = writeFile(buf) if err != nil { panic(err) } } func getLastDays(len int) []string { now := time.Now() getDay := func(t time.Time, dif int) string { return t.AddDate(0, 0, dif).Format("01/02") } var res []string for i := 1; i <= len; i++ { res = append(res, getDay(now, i-len)) } return res }