mbarchart.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. err := termui.Init()
  9. if err != nil {
  10. panic(err)
  11. }
  12. defer termui.Close()
  13. //termui.UseTheme("helloworld")
  14. bc := termui.NewMBarChart()
  15. math := []int{90, 85, 90, 80}
  16. english := []int{70, 85, 75, 60}
  17. science := []int{75, 60, 80, 85}
  18. compsci := []int{100, 100, 100, 100}
  19. bc.Data[0] = math
  20. bc.Data[1] = english
  21. bc.Data[2] = science
  22. bc.Data[3] = compsci
  23. studentsName := []string{"Ken", "Rob", "Dennis", "Linus"}
  24. bc.BorderLabel = "Student's Marks X-Axis=Name Y-Axis=Marks[Math,English,Science,ComputerScience] in %"
  25. bc.Width = 100
  26. bc.Height = 30
  27. bc.Y = 0
  28. bc.BarWidth = 10
  29. bc.DataLabels = studentsName
  30. bc.ShowScale = true //Show y_axis scale value (min and max)
  31. bc.SetMax(400)
  32. bc.TextColor = termui.ColorGreen //this is color for label (x-axis)
  33. bc.BarColor[3] = termui.ColorGreen //BarColor for computerscience
  34. bc.BarColor[1] = termui.ColorYellow //Bar Color for english
  35. bc.NumColor[3] = termui.ColorRed // Num color for computerscience
  36. bc.NumColor[1] = termui.ColorRed // num color for english
  37. //Other colors are automatically populated, btw All the students seems do well in computerscience. :p
  38. termui.Render(bc)
  39. termui.Handle("/sys/kbd/q", func(termui.Event) {
  40. termui.StopLoop()
  41. })
  42. termui.Loop()
  43. }