-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
74 lines (67 loc) · 1.38 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
"path/filepath"
"github.com/go-analyze/charts"
)
/*
Example line chart with the area below the line shaded.
*/
func writeFile(buf []byte) error {
tmpPath := "./tmp"
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}
file := filepath.Join(tmpPath, "line-chart-area.png")
return os.WriteFile(file, buf, 0600)
}
func main() {
values := [][]float64{
{
120,
132,
101,
134,
90,
230,
210,
},
}
p, err := charts.LineRender(
values,
charts.TitleTextOptionFunc("Line"),
charts.XAxisDataOptionFunc([]string{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun",
}),
charts.LegendOptionFunc(charts.LegendOption{
Data: []string{"Email"},
Padding: charts.Box{
Top: 5,
Bottom: 10,
},
}),
charts.YAxisOptionFunc(charts.YAxisOption{
Min: charts.FloatPointer(0.0), // ensure y-axis starts at 0
}),
// setup fill styling below
func(opt *charts.ChartOption) {
opt.FillArea = true // shade the area under the line
opt.FillOpacity = 150 // set the fill opacity a little lighter than default
opt.XAxis.BoundaryGap = charts.False() // BoundaryGap is less appealing when enabling FillArea
},
)
if err != nil {
panic(err)
}
if buf, err := p.Bytes(); err != nil {
panic(err)
} else if err = writeFile(buf); err != nil {
panic(err)
}
}