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.
85 lines
1.5 KiB
85 lines
1.5 KiB
package goCharts
|
|
|
|
/*
|
|
*
|
|
@author: sre
|
|
@date: 2022/9/17 0017
|
|
@desc: todo
|
|
*
|
|
*/
|
|
|
|
import (
|
|
"WechatGateWay/api"
|
|
"github.com/vicanso/go-charts/v2"
|
|
"log"
|
|
"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(symbol string) {
|
|
timeUpdate, symbolPriceETH := api.GetSerivers(symbol)
|
|
log.Println(timeUpdate, symbolPriceETH)
|
|
values := [][]float64{
|
|
symbolPriceETH,
|
|
//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(timeUpdate),
|
|
//charts.XAxisDataOptionFunc(getLastDays(30)),
|
|
charts.LegendLabelsOptionFunc([]string{
|
|
symbol,
|
|
//"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
|
|
}
|