asciigraph在命令行应用中绘制ASCII线条图的Go语言包

1313 2019-10-06 Go BSD v3 官方网站

在命令行应用中制作轻量级ASCII线条图╭┈╯的Go语言包,无需其他依赖项。

asciigraph下载

v0.4.0.zip(v0.4.1) 下载

v0.4.1.zip(v0.4.1) 下载

v0.3.0.zip(v0.4.1) 下载

v0.2.1.zip(v0.4.1) 下载

v0.1.0.zip(v0.4.1) 下载

v0.2.0.zip(v0.4.1) 下载

v0.1.1.zip(v0.4.1) 下载

asciigraph介绍

Build statusGo Report CardCoverage StatusGoDocLicenseMentioned in Awesome Go

在命令行应用中制作轻量级ASCII线条图╭┈╯的Go语言包,无需其他依赖项。

/pic/2c80b52774b04f5db30bff2ab7c76b99.png

安装

go get github.com/guptarohit/asciigraph

用法

基础图表

package 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 ┤   ╰╯    ╰╯╰╯

Command line interface

This package also brings a small utility for command line usage. Assuming$GOPATH/bin is in your $PATH, simply go get it then install CLI.

CLI Installation

go install github.com/guptarohit/asciigraph/cmd/asciigraph

Feed it data points via stdin:

$ seq 1 72 | asciigraph -h 10 -c "plot data from stdin"
72.00 ┼
65.55 ┤                                                                  ╭────
59.09 ┤                                                           ╭──────╯
52.64 ┤                                                    ╭──────╯
46.18 ┤                                             ╭──────╯
39.73 ┤                                      ╭──────╯
33.27 ┤                              ╭───────╯
26.82 ┤                       ╭──────╯
20.36 ┤                ╭──────╯
13.91 ┤         ╭──────╯
 7.45 ┤  ╭──────╯
 1.00 ┼──╯
         plot data from stdin

Acknowledgement

This package is golang port of library asciichart written by @kroitor.

Contributing

Feel free to make a pull request! :octocat: