-
Notifications
You must be signed in to change notification settings - Fork 0
/
line.go
50 lines (38 loc) · 1.15 KB
/
line.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package chart
import (
"errors"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/go-echarts/snapshot-chromedp/render"
modelresponse "github.com/namhq1989/maid-bots/internal/model/response"
"github.com/namhq1989/maid-bots/util/appcontext"
)
type MonitorResponseTimeLine struct {
Data []modelresponse.HealthCheckRecordResponseTimeChartData
}
func (c MonitorResponseTimeLine) ToImage(ctx *appcontext.AppContext) (string, error) {
l := len(c.Data)
if l == 0 {
return "", errors.New("no data")
}
var (
line = charts.NewLine()
xAxisData = make([]string, 0, l)
yAxisData = make([]opts.LineData, 0, l)
fileName = randomImageName()
)
line.SetGlobalOptions(
charts.WithAnimation(false),
)
for _, item := range c.Data {
xAxisData = append(xAxisData, item.Date)
yAxisData = append(yAxisData, opts.LineData{Value: item.Avg})
}
line.SetXAxis(xAxisData).
AddSeries("Average Response Time (Milliseconds) / UTC", yAxisData)
render.MakeChartSnapshot(line.RenderContent(), fileName)
ctx.Logger.Info("line chart generated", appcontext.Fields{
"filename": fileName,
})
return fileName, nil
}