Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

KittyChart

← Live demo: the same library in a browser canvas and in a terminal

Chart.js-compatible charts for terminals that can show images: kitty, Ghostty, WezTerm, Konsole and others through the kitty graphics protocol; foot, xterm, mlterm and Windows Terminal through sixel; and every other terminal as block and Braille characters.

You write a normal Chart.js configuration ({ type, data, options }). KittyChart renders it natively in Rust, with Chart.js’s defaults, layout and palette. It sizes the chart to your terminal’s cells and draws it at the cursor, with default colors taken from your terminal theme.

Gallery: every test fixture, on a white page and in a dark terminal.

Beyond plain JSON

  • Scriptable options: wherever Chart.js accepts a function, pass one. In Python and Node, put the function in the config itself. In JSON, put the marker {"__kc_fn": "name"} and register it: ChartConfig::with_fn("name", |ctx| …) in Rust, kc_chart_set_dispatch in C. The function gets Chart.js’s context object (type, datasetIndex, dataIndex, raw, parsed, chart.chartArea …). ticks.callback gets (value, index, ticks) as __args.
  • Gradients work in plain JSON wherever a color goes: {"type": "linear", "x0": 0, "y0": "bottom", "x1": 0, "y1": "top", "stops": [[0, "#36a2eb00"], [1, "#36a2eb"]]}. Radial and conic work too, and coordinates may be chart-area keywords (left, top, centerX …).
  • Line segment styles: segment: { borderColor, borderDash, borderWidth, backgroundColor … }, static or scriptable, with a segment context (p0, p1, p0DataIndex …).
  • SVG: kittychart chart.json --out chart.svg, render_svg(), to_svg(), toSvg() or kc_render_svg(). Text is drawn as outlines, so the file needs no fonts.

Command line

kittychart chart.json                    # draw in the terminal (kitty → sixel → text)
kittychart chart.json --out chart.png    # or render a PNG (or .svg)
cat chart.json | kittychart --protocol text --cols 80
kittychart chart.json --watch            # redraw in place whenever the file changes
kittychart view chart.json --watch       # explore it full-screen (below)

Interactive charts

kittychart view chart.json opens the chart full-screen. Hover shows Chart.js’s tooltip and hover styles, following the config’s interaction and hover options. Clicking a legend item hides that dataset (or that slice, on pie, doughnut and polar charts). With --watch, the chart animates to the file’s new contents whenever it changes.

Key
mousehover for tooltips; click legend items
← → Home Endstep through the data points
1–9toggle a dataset (a slice on arc charts)
lshow or hide the legend
rreplay the animation
ssave a PNG to the current directory
q, Escquit, restoring the screen

It works with kitty graphics, sixel and text. When the terminal says it can read local files or shared memory (kitty does), frames go that way instead of through the escape stream; otherwise they are sent inline (--no-fast-transfer forces that). Python and Node have the same viewer as chart.interact(), and the ratatui and Textual widgets handle hover, legend clicks and animation inside your own layout. Animations (Chart.js’s animation options) play only in these interactive views. A chart printed with show draws its final frame at once.

Python

pip install kittychart
import kittychart
chart = kittychart.Chart(type="bar", data={"labels": ["Q1", "Q2"], "datasets": [{"label": "Revenue", "data": [12, 19]}]})
chart.show()

numpy, pandas and polars data, Python functions as scriptable options, Rich layouts, a Textual widget with hover, terminal IPython and Jupyter, and chart.interact(). See the Python README.

Node.js, Bun, Deno

npm install kittychart
const { Chart } = require('kittychart')
new Chart({ type: 'line', data: { labels: ['a', 'b'], datasets: [{ label: 'x', data: [1, 3] }] } }).show()

Typed arrays, Dates, JS functions as scriptable options, chart.interact(), and typings that accept Chart.js’s own ChartConfiguration. Prebuilt for glibc and musl (Alpine) Linux, macOS and Windows. See the Node README.

Rust

#![allow(unused)]
fn main() {
let config = kittychart::ChartConfig::from_json(json)?;
kittychart::show::show(config, &Default::default())?;              // draw in the terminal
let png = kittychart::render_json(json, &kittychart::RenderOptions::new(800.0))?.to_png();
}

kittychart-ratatui is a ratatui widget (kitty graphics through Unicode placeholders, or text). Its ChartState handles hover (handle_mouse), legend clicks (handle_click) and animation (set_time, is_animating); see examples/dashboard.rs. kittychart::interact is the full-screen viewer, and kittychart::session::Session is its sans-IO core for other hosts.

C and other languages

A C ABI with a generated header: see the C guide. It works from any language with a C FFI (Go, Zig, Ruby, Lua, Swift …).

How it chooses what to draw

protocol: auto (the default, or $KITTYCHART_PROTOCOL) asks the terminal what it supports. It uses kitty graphics if available, then sixel, then text. Inside tmux, kitty images go through passthrough as Unicode placeholders (needs set -g allow-passthrough on). Without a terminal (a pipe, CI), charts are drawn as text on stdout. Detection works on Unix and, using the console’s virtual-terminal mode, on Windows (sixel in Windows Terminal, kitty graphics in WezTerm). The Windows path cross-compiles and passes clippy, but hasn’t been run in a real Windows terminal yet. PNG and SVG output work everywhere.

kittychart (Python)

Chart.js-compatible charts for graphics-capable terminals. Draws with the kitty graphics protocol (kitty, Ghostty, WezTerm, Konsole …), sixel (foot, xterm, mlterm, Windows Terminal …) or block and Braille characters anywhere else. The renderer is Rust; no browser or Node.

import kittychart

chart = kittychart.Chart(
    type="line",
    data={
        "labels": ["Mon", "Tue", "Wed", "Thu", "Fri"],
        "datasets": [{"label": "Requests", "data": [120, 190, 170, 250, 210], "fill": True}],
    },
    options={"plugins": {"title": {"display": True, "text": "This week"}}},
)
chart.show()                       # draw at the cursor
chart.save("chart.png", width=800, scale=2)   # or "chart.svg"
print(chart.to_text(cols=60))      # block/Braille text with ANSI colors

Any Chart.js configuration works: the same type, data and options, the same defaults. Charts take their default colors from your terminal theme (colors="chartjs" to opt out).

Data: numpy arrays, pandas and polars Series, datetimes (time scales) and NaN (a gap) can go straight into data. Chart.from_dataframe(df, x="date", y=["a", "b"]) makes one dataset per column, for pandas or polars.

Rich: rich.print(chart), or put a chart in a Panel, Table or Columns. With kitty graphics the image lives in Rich’s layout through Unicode placeholders.

Functions as options: wherever Chart.js takes a function, pass a Python callable. It gets Chart.js’s context (ctx.raw, ctx.dataIndex, ctx.chart.chartArea …); tick callbacks get (value, index, ticks):

kittychart.Chart(
    type="bar",
    data={"labels": ["a", "b", "c"], "datasets": [{"data": [5, 15, 8],
        "backgroundColor": lambda ctx: "#e74c3c" if ctx.raw > 10 else "#3498db"}]},
    options={"scales": {"y": {"ticks": {"callback": lambda value, i, ticks: f"${value}"}}}},
).show()

Interactive: chart.interact() explores the chart full-screen until q: hover for tooltips, click legend items to hide datasets, arrows to step through the data, r replays the animation, s saves a PNG. chart.interact(watch="chart.json") animates to that file’s contents whenever it changes.

Textual: from kittychart.textual import ChartWidget; ChartWidget(chart) fills its area, redraws on resize, shows tooltips on hover, toggles datasets on legend clicks, and animates when widget.chart = new_chart updates it.

IPython / Jupyter: in terminal IPython, displaying a chart (chart on its own line) draws it. Jupyter (and euporie) show it as a PNG.

show() options: protocol (“auto”, “kitty”, “sixel”, “text”, “blocks”, “half”, “braille”; default $KITTYCHART_PROTOCOL or “auto”), cols/rows (cells), width/height (CSS px), scale, background, placeholders (kitty Unicode placeholders, automatic inside tmux), force (skip detection), colors (“terminal” or “chartjs”).

kittychart (Node.js, Bun, Deno)

Chart.js-compatible charts for graphics-capable terminals. Draws with the kitty graphics protocol (kitty, Ghostty, WezTerm, Konsole …), sixel (foot, xterm, mlterm, Windows Terminal …) or block and Braille characters anywhere else. The renderer is native (Rust, via Node-API); no browser or canvas package.

const { Chart } = require('kittychart') // or: import { Chart } from 'kittychart'

const chart = new Chart({
  type: 'bar',
  data: {
    labels: ['Q1', 'Q2', 'Q3', 'Q4'],
    datasets: [{ label: 'Revenue', data: [12, 19, 7, 15] }],
  },
  options: { plugins: { title: { display: true, text: 'Quarterly revenue' } } },
})

chart.show()                                    // draw at the cursor
fs.writeFileSync('chart.png', chart.toPng({ width: 800, scale: 2 }))
console.log(chart.toText({ cols: 60 }))         // block/Braille text with ANSI colors
fs.writeFileSync('chart.svg', chart.toSvg())    // SVG, text as outlines

Any Chart.js configuration works, and the typings accept Chart.js’s own ChartConfiguration types, so existing configs carry over. Charts take their default colors from your terminal theme (colors: 'chartjs' to opt out).

  • Data: typed arrays (Float64Array …), BigInts, Dates (time scales) and NaN (a gap) can go straight into data.
  • show(opts): protocol (‘auto’, ‘kitty’, ‘sixel’, ‘text’, ‘blocks’, ‘half’, ‘braille’; default $KITTYCHART_PROTOCOL or ‘auto’), cols/rows (cells), width/height (CSS px), scale, background, placeholders (kitty Unicode placeholders; automatic inside tmux), force (skip detection), colors.
  • TUI frameworks: probe() once, then chart.prepare(info, { placeholders: true }) returns the escapes (data.subarray(0, graphicsLen)) and placeholder text to place in your layout.
  • update({ options, data }) merges changes; toRgba() returns raw pixels.
  • Functions as options: wherever Chart.js takes a function, pass one. It gets Chart.js’s context (ctx.raw, ctx.dataIndex …); tick callbacks get (value, index, ticks): backgroundColor: (ctx) => (ctx.raw > 10 ? 'red' : 'blue').
  • interact(opts): explore the chart full-screen until q: hover for tooltips, click legend items to hide datasets, arrows to step, r replays the animation, s saves a PNG. { watch: 'chart.json' } animates to that file’s contents when it changes. Blocks.

Works in Node.js ≥ 18, Bun and Deno (deno run -A), with prebuilt modules for Linux (glibc and musl, x64 and arm64), macOS and Windows. Terminal detection on Windows (console virtual-terminal mode) is built but not yet tried in a real Windows terminal. PNG, SVG and RGBA rendering work everywhere.

C API

The C library is crates/kittychart-ffi. The header is include/kittychart.h, generated from the Rust source by cbindgen; just header regenerates it, and a test fails when it’s stale.

cargo build --release -p kittychart-ffi
# → target/release/libkittychart_ffi.{a,so,dylib} (kittychart_ffi.dll + .lib on Windows)
cc app.c -Icrates/kittychart-ffi/include target/release/libkittychart_ffi.a -lm -lpthread -ldl

Release archives contain the header, the static and shared libraries, and the CLI.

#include "kittychart.h"

kc_chart *chart = kc_chart_from_json("{\"type\":\"bar\",\"data\":{\"labels\":[\"a\",\"b\"],"
                                     "\"datasets\":[{\"label\":\"x\",\"data\":[1,2]}]}}");
if (!chart) { fprintf(stderr, "%s\n", kc_last_error()); return 1; }

kc_show(chart, NULL);                                     /* draw in the terminal */

kc_render_options ro = { .width = 800, .scale = 2, .background = "white" };
kc_bytes png;
if (kc_render_png(chart, &ro, &png) == 0) {
    fwrite(png.data, 1, png.len, file);
    kc_bytes_free(png);
}
kc_chart_free(chart);
Function
kc_chart_from_json(json)Parse a Chart.js config. NULL on error.
kc_chart_set_json(chart, json)Replace the config (new data). Unchanged on error.
kc_render_png(chart, opts, &bytes)PNG in memory.
kc_render_rgba(chart, opts, &image)Raw RGBA8 pixels.
kc_render_text(chart, cols, rows, mode, &bytes)Block/Braille text with ANSI colors (NUL-terminated).
kc_render_svg(chart, opts, &bytes)SVG (text as outlines; NUL-terminated).
kc_show(chart, opts)Detect the terminal and draw at the cursor (Unix; Windows unverified).
kc_chart_set_dispatch(chart, fn, user)Call fn for scriptable options (see below).
kc_bytes_free(bytes)Free returned memory (including kc_image.rgba).
kc_last_error()Message for the last failure on this thread.
kc_chart_free(chart), kc_version()

Scriptable options

Wherever Chart.js takes a function, put {"__kc_fn": "<id>"} in the JSON and register one dispatch function. It gets the id and Chart.js’s context object as JSON (type, datasetIndex, dataIndex, raw, parsed, chart …; positional arguments such as ticks.callback’s (value, index, ticks) are in "__args"). It returns the option’s value as JSON, valid until the next call, or NULL for “undefined” (the next scope’s value applies).

static const char *color(const char *id, const char *ctx, void *user) {
    if (strcmp(id, "color") != 0) return NULL;
    return strstr(ctx, "\"dataIndex\":1,") ? "\"#ff0000\"" : "\"#0000ff\"";
}

kc_chart *c = kc_chart_from_json("{\"type\":\"bar\",\"data\":{\"labels\":[\"a\",\"b\"],"
    "\"datasets\":[{\"data\":[1,2],\"backgroundColor\":{\"__kc_fn\":\"color\"}}]}}");
kc_chart_set_dispatch(c, color, NULL);

The function is called on the thread that renders. Invalid JSON from it fails the render with a message in kc_last_error().

Conventions:

  • Functions return 0 on success and -1 on failure. Options pointers may be NULL, and zero or NULL fields mean “default”.
  • Returned buffers are NUL-terminated (not counted in len).
  • Panics never cross the boundary.

The tests compile tests/c/smoke.c against the header and check its PNG against the Rust render byte for byte. They also check it under AddressSanitizer locally, and run examples/show.c in Ghostty’s VT core.

Gallery

Every chart in tests/fixtures/, each a plain Chart.js configuration. Left: Chart.js’s default colors on a white page. Right: the same config in a dark terminal (Tokyo Night), with default colors derived from the terminal’s theme.

Regenerate with just gallery.

animation

animation-bar_300ms

animation-doughnut_400ms

animation-line_500ms

animation-polarArea_250ms

animation-radar_600ms

animation-update_bar_line_400ms

arc

arc-doughnut_rings

arc-half_gauge

arc-pie

bar

bar-floating

bar-grouped

bar-horizontal

bar-stacked

bubble

bubble-basic

decimation

decimation-lttb

decimation-min-max

fill

fill-origin_above_below

fill-radar_circular_origin

fill-radar_default

fill-stacked_area

fill-start_end_value

gradient

gradient-area_linear

gradient-bar_radial_doughnut_conic

hover

hover-bar

hover-doughnut

hover-line_doughnut

line

line-basic

line-scales_and_titles

line-stepped_monotone_points

mixed

mixed-bar_line_dpr2

radial

radial-polar

radial-radar

scales

scales-log_bar_zero

scales-log_line

scatter

scatter-basic

segment

segment-static_dash_fill

time

time-daily_line

time-hourly_irregular

time-monthly_bar_week_unit

time-timeseries_gaps

toggle

toggle-bar_hidden

toggle-doughnut_data

toggle-polar_data

tooltip

tooltip-bar_index

tooltip-doughnut

tooltip-line_nearest_pointstyle

tooltip-scatter_bottom_left

tooltip-scatter_edges