simple-ascii-chart

Render ASCII charts from TypeScript for command-line tools, logs, API responses, text dashboards, and documentation.

simple-ascii-chart

simple-ascii-chart is a TypeScript library that renders charts as plain text. It draws line, point, bar, candlestick, heatmap, and sparkline charts, and bins raw samples into histogram data. Line, point, and bar charts support multiple series, ANSI colors, thresholds, legends, and axis labels, and can be drawn with Braille characters.

Animated sine and cosine chart drawn by simple-ascii-chart
Example code
let step = 0;
const interval = 0.1;
const maxPoints = 20;
const sinPoints: Point[] = [];
const cosPoints: Point[] = [];

setInterval(() => {
  console.clear();

  sinPoints.push([step, Math.sin(step)]);
  cosPoints.push([step, Math.cos(step)]);

  if (sinPoints.length > maxPoints) sinPoints.shift();
  if (cosPoints.length > maxPoints) cosPoints.shift();

  console.log(
    plot([sinPoints, cosPoints], {
      showTickLabel: true,
      color: ['ansiRed', 'ansiBlue'],
      width: 120,
      height: 16,
      yRange: [-1, 1],
      xLabel: 'Step (π)',
      yLabel: 'Amplitude',
      legend: { position: 'bottom', series: ['Sine', 'Cosine'] },
      axisCenter: [undefined, 0],
      formatter: (x, { axis }) => {
        if (axis === 'y') return x;
        return `${(x / Math.PI).toFixed(1)}π`;
      },
    }),
  );

  step += interval;
}, 200);

Each chart is returned as a string, and the library has no runtime dependencies. Use it where graphics are not available: command-line tools, build logs, API responses, and diagnostics.

Project article

An article on gtktsc.com explains the design choices behind simple-ascii-chart and its CLI, from readable defaults to shell pipelines: What simple-ascii-chart taught me about API design.

Support

If this project helps you, you can support its development: Buy me a coffee.