Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1d2eb22 Jul 23, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/asciigraph Add newline to end of usage message Jun 28, 2018
examples Implement functional options Jun 26, 2018
.gitignore .gitignore Mar 5, 2018
.travis.yml Update .travis.yml Jun 23, 2018
LICENSE Add LICENSE Feb 28, 2018
README.rst Update README.rst Jun 28, 2018
asciigraph.go Shortened a bit ) Jul 23, 2018
asciigraph_test.go Add test case Jul 3, 2018
options.go Implement functional options Jun 26, 2018
utils.go Add 'width' config option Jun 23, 2018

README.rst

asciigraph

Build status Go Report Card Coverage Status GoDoc License

Go package to make lightweight ASCII line graphs ╭┈╯.

https://user-images.githubusercontent.com/7895001/41509956-b1b2b3d0-7279-11e8-9d19-d7dea17d5e44.png

Installation

go get github.com/guptarohit/asciigraph

Usage

Basic graph

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)
}

Running this example would render the following 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: