asciiplot

1.0.0 • Public • Published

asciiplot

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

Console ASCII Line charts in pure Javascript (for NodeJS)

Usage

NodeJS

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

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 (* ((Math.PI * 4) / s0.length))
console.log (asciiplot.plot (s0))
Console ASCII Line charts in pure Javascript (for NodeJS)

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

Auto-range

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

Package Sidebar

Install

npm i asciiplot

Weekly Downloads

11

Version

1.0.0

License

PUBLIC_DOMAIN

Unpacked Size

8.12 kB

Total Files

4

Last publish

Collaborators

  • buzuli