-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
60 lines (54 loc) · 1.34 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
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/go-analyze/charts"
)
/*
Example basic scatter chart with a variety of basic configuration options shown.
*/
func writeFile(buf []byte) error {
tmpPath := "./tmp"
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}
file := filepath.Join(tmpPath, "scatter-chart-1-basic.png")
return os.WriteFile(file, buf, 0600)
}
func main() {
values := [][]float64{
{120, 132, 101, charts.GetNullValue(), 90, 230, 210},
{220, 182, 191, 234, 290, 330, 310},
{150, 232, 201, 154, 190, 330, 410},
{320, 332, 301, 334, 390, 330, 320},
{820, 932, 901, 934, 1290, 1330, 1320},
}
p, err := charts.ScatterRender(
values,
charts.TitleTextOptionFunc("Scatter"),
charts.XAxisLabelsOptionFunc([]string{
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
}),
charts.LegendLabelsOptionFunc([]string{
"Email", "Union Ads", "Video Ads", "Direct", "Search Engine",
}),
func(opt *charts.ChartOption) {
opt.Title.FontStyle.FontSize = 16
opt.Legend.Padding = charts.Box{
Left: 100,
}
opt.Symbol = charts.SymbolCircle
opt.ValueFormatter = func(f float64) string {
return fmt.Sprintf("%.0f", f)
}
},
)
if err != nil {
panic(err)
} else if buf, err := p.Bytes(); err != nil {
panic(err)
} else if err = writeFile(buf); err != nil {
panic(err)
}
}