get last 30 days
continuous-integration/drone/push Build is passing Details

master
dustoair 3 years ago
parent 4f60ab046e
commit a175f800cc

@ -25,10 +25,10 @@ func getRand(len int) []float64 {
func Draw() { func Draw() {
values := [][]float64{ values := [][]float64{
getRand(7), getRand(30),
getRand(7), getRand(30),
getRand(7), getRand(30),
getRand(7), getRand(30),
} }
p, err := charts.LineRender( p, err := charts.LineRender(
values, values,
@ -37,7 +37,7 @@ func Draw() {
charts.WidthOptionFunc(720), charts.WidthOptionFunc(720),
charts.HeightOptionFunc(1280), charts.HeightOptionFunc(1280),
charts.TitleTextOptionFunc("symbol price"), charts.TitleTextOptionFunc("symbol price"),
charts.XAxisDataOptionFunc(getLastDays()), charts.XAxisDataOptionFunc(getLastDays(30)),
charts.LegendLabelsOptionFunc([]string{ charts.LegendLabelsOptionFunc([]string{
"BTC", "BTC",
"ETH", "ETH",
@ -68,18 +68,14 @@ func Draw() {
} }
} }
func getLastDays() []string { func getLastDays(len int) []string {
now := time.Now() now := time.Now()
getDay := func(t time.Time, dif int) string { getDay := func(t time.Time, dif int) string {
return t.AddDate(0, 0, dif).Format("01/02") return t.AddDate(0, 0, dif).Format("01/02")
} }
return []string{ var res []string
getDay(now, -6), for i := 1; i <= len; i++ {
getDay(now, -5), res = append(res, getDay(now, i-len))
getDay(now, -4),
getDay(now, -3),
getDay(now, -2),
getDay(now, -1),
getDay(now, 0),
} }
return res
} }

Loading…
Cancel
Save