Skip to main content

Nice-looking lightweight console ASCII line charts ╭┈╯ with no dependencies

Project description

asciichart

npm PyPI Travis Coverage Status license

Console ASCII line charts in pure Javascript (for NodeJS and browsers) with no dependencies. This code is absolutely free for any usage, you just do whatever the fuck you want.

Console ASCII Line charts in pure Javascript (for NodeJS and browsers)

Usage

NodeJS

npm install asciichart
var asciichart = require ('asciichart')
var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
    s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))

Browsers

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta charset="UTF-8">
        <title>asciichart</title>
        <script src="asciichart.js"></script>
        <script type="text/javascript">
            var s0 = new Array (120)
            for (var i = 0; i < s0.length; i++)
                s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
            console.log (asciichart.plot (s0))
        </script>
    </head>
    <body>
    </body>
</html>

Options

The width of the chart will always equal the length of data series. The height and range are determined automatically.

var s0 = new Array (120)
for (var i = 0; i < s0.length; i++)
    s0[i] = 15 * Math.sin (i * ((Math.PI * 4) / s0.length))
console.log (asciichart.plot (s0))
Console ASCII Line charts in pure Javascript (for NodeJS and browsers)

The output can be configured by passing a second parameter to the plot (series, config) function. The following options are supported:

var config = {

    offset:  3,          // axis offset from the left (min 2)
    padding: '       ',  // padding string for label formatting (can be overrided)
    height:  10,         // any height you want

    // the label format function applies default padding
    format:  function (x, i) { return (padding + x.toFixed (2)).slice (-padding.length) }
}

Scale To Desired Height

Console ASCII Line charts in pure Javascript (for NodeJS and browsers)
var s = []
for (var i = 0; i < 120; i++)
    s[i] = 15 * Math.cos (i * ((Math.PI * 8) / 120)) // values range from -15 to +15
console.log (asciichart.plot (s, { height: 6 }))     // this rescales the graph to ±3 lines
Console ASCII Line charts in pure Javascript (for NodeJS and browsers)

Auto-range

var s2 = new Array (120)
s2[0] = Math.round (Math.random () * 15)
for (i = 1; i < s2.length; i++)
    s2[i] = s2[i - 1] + Math.round (Math.random () * (Math.random () > 0.5 ? 2 : -2))
console.log (asciichart.plot (s2))
Console ASCII Line charts in pure Javascript (for NodeJS and browsers)

See Also

A util by madnight for drawing Bitcoin/Ether/altcoin charts in command-line console: bitcoin-chart-cli.

bitcoin-chart-cli

Ports

Special thx to all who helped port it to other languages, great stuff!

Future work (coming soon, hopefully)

  • multi-line colored charts in console!
  • levels and points on the graph!
  • even better value formatting and auto-scaling!

preview

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asciichartpy-1.5.10.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

asciichartpy-1.5.10-py2.py3-none-any.whl (6.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file asciichartpy-1.5.10.tar.gz.

File metadata

  • Download URL: asciichartpy-1.5.10.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for asciichartpy-1.5.10.tar.gz
Algorithm Hash digest
SHA256 b9650bbb01f573095a9ea9b8941f2fb26c14f737dcc7bdbee4c49e5c123bfff4
MD5 c097be261a871dffbeedaf0702fb2e75
BLAKE2b-256 ad18bfd55d1bd38a75c6e590090af577c5cde779a7aa9e0fff86d070f0f72c99

See more details on using hashes here.

File details

Details for the file asciichartpy-1.5.10-py2.py3-none-any.whl.

File metadata

  • Download URL: asciichartpy-1.5.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for asciichartpy-1.5.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 347afa57fe6ec2eb734f3c930a813f550b4189c9f3984e41fca53cdff1c3fe7c
MD5 75779a975f8cf3f15095b6bc6fd019b8
BLAKE2b-256 80f47798c48179603cde3a27db1bb2f60fe8e6dd01bf41f8f6da6383b5f03ec5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page