From a175f800cc4566a136aaac8d1c1b7870ee0ee70c Mon Sep 17 00:00:00 2001 From: dustoair <107600816+dustoair@users.noreply.github.com> Date: Sat, 17 Sep 2022 17:52:56 +0800 Subject: [PATCH] get last 30 days --- goCharts/draw.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/goCharts/draw.go b/goCharts/draw.go index 3367943..68cac43 100644 --- a/goCharts/draw.go +++ b/goCharts/draw.go @@ -25,10 +25,10 @@ func getRand(len int) []float64 { func Draw() { values := [][]float64{ - getRand(7), - getRand(7), - getRand(7), - getRand(7), + getRand(30), + getRand(30), + getRand(30), + getRand(30), } p, err := charts.LineRender( values, @@ -37,7 +37,7 @@ func Draw() { charts.WidthOptionFunc(720), charts.HeightOptionFunc(1280), charts.TitleTextOptionFunc("symbol price"), - charts.XAxisDataOptionFunc(getLastDays()), + charts.XAxisDataOptionFunc(getLastDays(30)), charts.LegendLabelsOptionFunc([]string{ "BTC", "ETH", @@ -68,18 +68,14 @@ func Draw() { } } -func getLastDays() []string { +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") } - return []string{ - getDay(now, -6), - getDay(now, -5), - getDay(now, -4), - getDay(now, -3), - getDay(now, -2), - getDay(now, -1), - getDay(now, 0), + var res []string + for i := 1; i <= len; i++ { + res = append(res, getDay(now, i-len)) } + return res }