-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.1 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
package main
import (
"image/color"
"github.com/fogleman/gg"
"github.com/warmans/gochart"
)
const numPoints = 23
func main() {
canvas := gg.NewContext(800, 400)
canvas.SetColor(color.White)
canvas.DrawRectangle(0, 0, float64(canvas.Width()), float64(canvas.Height()))
canvas.Fill()
series := gochart.NewTimeSeries(gochart.GenTimes(numPoints), gochart.GenTestData(numPoints))
yScale := gochart.NewYScale(10, series)
xScale := gochart.NewXScale(series, 0)
grid := gochart.New12ColGridLayout(
gochart.GridRow{
HeightPercent: 0.95,
Columns: []gochart.GridColumn{
{
ColSpan: 1,
El: gochart.NewYAxis(
yScale,
),
},
{
ColSpan: 11,
El: gochart.NewLinesPlot(
yScale,
xScale,
series,
),
},
},
},
gochart.GridRow{
HeightPercent: 0.05,
Columns: []gochart.GridColumn{
{ColSpan: 1},
{
ColSpan: 11,
El: gochart.NewXAxis(
series,
xScale,
),
},
},
},
)
grid.Render(canvas, gochart.BoundingBoxFromCanvas(canvas))
if err := canvas.SavePNG("./example.png"); err != nil {
panic(err)
}
}