-
Notifications
You must be signed in to change notification settings - Fork 786
/
barchart.go
42 lines (34 loc) · 906 Bytes
/
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
// 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()
bc := widgets.NewBarChart()
bc.Data = []float64{3, 2, 5, 3, 9, 3}
bc.Labels = []string{"S0", "S1", "S2", "S3", "S4", "S5"}
bc.Title = "Bar Chart"
bc.SetRect(5, 5, 100, 25)
bc.BarWidth = 5
bc.BarColors = []ui.Color{ui.ColorRed, ui.ColorGreen}
bc.LabelStyles = []ui.Style{ui.NewStyle(ui.ColorBlue)}
bc.NumStyles = []ui.Style{ui.NewStyle(ui.ColorYellow)}
ui.Render(bc)
uiEvents := ui.PollEvents()
for {
e := <-uiEvents
switch e.ID {
case "q", "<C-c>":
return
}
}
}