You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
1.4 KiB

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(7),
getRand(7),
getRand(7),
getRand(7),
}
p, err := charts.LineRender(
values,
//charts.SVGTypeOption(),
charts.ThemeOptionFunc(charts.ThemeGrafana),
charts.WidthOptionFunc(720),
charts.HeightOptionFunc(1280),
charts.TitleTextOptionFunc("symbol price"),
charts.XAxisDataOptionFunc(getLastDays()),
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() []string {
now := time.Now()
getDay := func(t time.Time, dif int) string {
return t.AddDate(0, 0, dif).Format("01/02")
}
return []string{
getDay(now, -6),
getDay(now, -5),
getDay(now, -4),
getDay(now, -3),
getDay(now, -2),
getDay(now, -1),
getDay(now, 0),
}
}