barchart.go 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2017 Zack Guo <zack.y.guo@gmail.com>. All rights reserved.
  2. // Use of this source code is governed by a MIT license that can
  3. // be found in the LICENSE file.
  4. // +build ignore
  5. package main
  6. import "notabug.org/themusicgod1/termui"
  7. func main() {
  8. if err := termui.Init(); err != nil {
  9. panic(err)
  10. }
  11. defer termui.Close()
  12. bc := termui.NewBarChart()
  13. data := []int{3, 2, 5, 3, 9, 5, 3, 2, 5, 8, 3, 2, 4, 5, 3, 2, 5, 7, 5, 3, 2, 6, 7, 4, 6, 3, 6, 7, 8, 3, 6, 4, 5, 3, 2, 4, 6, 4, 8, 5, 9, 4, 3, 6, 5, 3, 6}
  14. bclabels := []string{"S0", "S1", "S2", "S3", "S4", "S5"}
  15. bc.BorderLabel = "Bar Chart"
  16. bc.Data = data
  17. bc.Width = 26
  18. bc.Height = 10
  19. bc.DataLabels = bclabels
  20. bc.TextColor = termui.ColorGreen
  21. bc.BarColor = termui.ColorRed
  22. bc.NumColor = termui.ColorYellow
  23. termui.Render(bc)
  24. termui.Handle("/sys/kbd/q", func(termui.Event) {
  25. termui.StopLoop()
  26. })
  27. termui.Loop()
  28. }