-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
70 lines (62 loc) · 1.33 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
package main
import (
"os"
"path/filepath"
"github.com/go-analyze/charts"
)
/*
Example radar chart with a variety of basic configuration options shown using the Painter API.
*/
func writeFile(buf []byte) error {
tmpPath := "./tmp"
if err := os.MkdirAll(tmpPath, 0700); err != nil {
return err
}
file := filepath.Join(tmpPath, "radar-chart-2.png")
return os.WriteFile(file, buf, 0600)
}
func main() {
values := [][]float64{
{4200, 3000, 20000, 35000, 50000, 18000},
{5000, 14000, 28000, 26000, 42000, 21000},
}
opt := charts.NewRadarChartOptionWithData(values,
[]string{
"Sales",
"Administration",
"Information Technology",
"Customer Support",
"Development",
"Marketing",
},
[]float64{
6500,
16000,
30000,
38000,
52000,
25000,
})
opt.Title = charts.TitleOption{
Text: "Basic Radar Chart",
FontStyle: charts.NewFontStyleWithSize(16),
}
opt.Legend = charts.LegendOption{
Data: []string{
"Allocated Budget", "Actual Spending",
},
Offset: charts.OffsetRight,
}
p := charts.NewPainter(charts.PainterOptions{
OutputFormat: charts.ChartOutputPNG,
Width: 600,
Height: 400,
})
if err := p.RadarChart(opt); err != nil {
panic(err)
} else if buf, err := p.Bytes(); err != nil {
panic(err)
} else if err = writeFile(buf); err != nil {
panic(err)
}
}