-
Notifications
You must be signed in to change notification settings - Fork 787
/
stacked_barchart.go
44 lines (35 loc) · 989 Bytes
/
stacked_barchart.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
// Copyright 2017 Zack Guo <[email protected]>. All rights reserved.
// Use of this source code is governed by a MIT license that can
// be found in the LICENSE file.
// +build ignore
package main
import (
"log"
ui "github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)
func main() {
if err := ui.Init(); err != nil {
log.Fatalf("failed to initialize termui: %v", err)
}
defer ui.Close()
sbc := widgets.NewStackedBarChart()
sbc.Title = "Student's Marks: X-Axis=Name, Y-Axis=Grade% (Math, English, Science, Computer Science)"
sbc.Labels = []string{"Ken", "Rob", "Dennis", "Linus"}
sbc.Data = make([][]float64, 4)
sbc.Data[0] = []float64{90, 85, 90, 80}
sbc.Data[1] = []float64{70, 85, 75, 60}
sbc.Data[2] = []float64{75, 60, 80, 85}
sbc.Data[3] = []float64{100, 100, 100, 100}
sbc.SetRect(5, 5, 100, 30)
sbc.BarWidth = 5
ui.Render(sbc)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
}
}
}