用于在命令行应用中绘制轻量级ASCII折线图的Go包,无其他依赖。
[![构建状态][]][1] [![Go 报告卡][]][2] [![覆盖率状态][]][3] [![GoDoc][]][4] [![许可证][]][5] [![在 Awesome Go 中被提及][]][6]
用于制作轻量级 ASCII 折线图的 Go 包 ╭┈╯。
go get -u github.com/guptarohit/asciigraph@latestpackage main
import (
"fmt"
"github.com/guptarohit/asciigraph"
)
func main() {
data := []float64{3, 4, 9, 6, 2, 4, 5, 8, 5, 10, 2, 7, 2, 5, 6}
graph := asciigraph.Plot(data)
fmt.Println(graph)
}运行此示例将渲染以下图表:
10.00 ┤ ╭╮
9.00 ┤ ╭╮ ││
8.00 ┤ ││ ╭╮││
7.00 ┤ ││ ││││╭╮
6.00 ┤ │╰╮ ││││││ ╭
5.00 ┤ │ │ ╭╯╰╯│││╭╯
4.00 ┤╭╯ │╭╯ ││││
3.00 ┼╯ ││ ││││
2.00 ┤ ╰╯ ╰╯╰╯package main
import (
"fmt"
"github.com/guptarohit/asciigraph"
)
func main() {
data := [][]float64{{0, 1, 2, 3, 3, 3, 2, 0}, {5, 4, 2, 1, 4, 6, 6}}
graph := asciigraph.PlotMany(data)
fmt.Println(graph)
}运行此示例将渲染以下图表:
6.00 ┤ ╭─
5.00 ┼╮ │
4.00 ┤╰╮ ╭╯
3.00 ┤ │╭│─╮
2.00 ┤ ╰╮│ ╰╮
1.00 ┤╭╯╰╯ │
0.00 ┼╯ ╰使用 YAxisValueFormatter(...) 来控制 Y 轴上打印的值的渲染方式。
这对于人类可读的单位(如字节、时长或特定领域的标签)非常有用。
package main
import (
"fmt"
"github.com/guptarohit/asciigraph"
)
func main() {
data := []float64{
30 * 1024 * 1024 * 1024,
70 * 1024 * 1024 * 1024,
2 * 1024 * 1024 * 1024,
}
graph := asciigraph.Plot(data,
asciigraph.Height(5),
asciigraph.Width(45),
asciigraph.YAxisValueFormatter(func(v float64) string {
return fmt.Sprintf("%.2f GiB", v/1024/1024/1024)
}),
)
fmt.Println(graph)
}运行此示例将渲染以下图形:
70.00 GiB ┤ ╭──────╮
56.40 GiB ┤ ╭───────╯ ╰────╮
42.80 GiB ┤ ╭──────╯ ╰───╮
29.20 GiB ┼──╯ ╰────╮
15.60 GiB ┤ ╰───╮
2.00 GiB ┤![image][]
暂无开放 Issues,或尚未同步最近议题。