examples

package module
v2.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 0 Imported by: 0

README

Examples

Starting with the v2.4.0 release, run examples without cloning the repository:

go run github.com/NimbleMarkets/ntcharts/examples/v2/quickstart@latest
go run github.com/NimbleMarkets/ntcharts/examples/v2/barchart/vertical@latest

Use @v2.4.0 instead of @latest to select that release. GPU shaders have their own module: go run github.com/NimbleMarkets/ntcharts/examples/shaders/v2@latest.

When you run task, all of the examples are built into the the bin directory of ntcharts. So run any example below like so: ./bin/ntcharts-quickstart.

These examples are live at https://nimblemarkets.github.io/ntcharts/. They were compiled to WASM and embedded in HTML using NimbleMarkets/go-booba.

The shader gallery runs six animated WGSL presets inside the terminal, with fullscreen, parameter controls and live rendering/encoding timings. It has an isolated go.mod, is included in the default example build, and runs in the live gallery on browsers with WebGPU, both as a Go build and as a TinyGo build of the same source:

task shaders
# Or: task shaders -- -fullscreen -slideshow=8s

Quickstart

This tutorial creates a simple Time Series Chart with two data sets utilizing the Bubble Tea framework, Lip Gloss for styling and BubbleZone for mouse support.

ntcharts-quickstart (source)
quickstart gif

Canvas

A Canvas provides a 2D grid to plot arbitrary runes supporting Lip Gloss styles and uses BubbleZone for mouse support.

ntcharts-canvas-logo (source)
logo canvas gif

Graphing

There are various graphing functions for drawing runes onto the Canvas.

Braille

ntcharts-graph-braille (source)
braille graph gif

Candlesticks

ntcharts-graph-candlesticks (source)
candlesticks graph gif

Circles

ntcharts-graph-circles (source)
circles graph gif

Columns

ntcharts-graph-columns (source)
columns graph gif

Lines

ntcharts-graph-lines (source)
lines graph gif

Rows

ntcharts-graph-rows (source)
rows graph gif

Bar Chart

Barcharts displays values as either horizontal rows or vertical columns. Negative values extend from the axis in the opposite direction of positive values, so one chart can show both. The axis follows the data range automatically, or is fixed with WithMaxValue and WithMinValue.

Rows

ntcharts-barchart-horizontal (source)
horizontal barchart gif

Columns

ntcharts-barchart-vertical (source)
vertical barchart gif

Line Chart

Linecharts displays (X,Y) data points onto a 2D grid in various types of charts.

Circles

Circles can be displayed with a given point and radius.

ntcharts-linechart-circles (source)
circles linechart gif

Lines

Lines can be displayed between two points.

ntcharts-linechart-lines (source)
lines linechart gif

Scatter

Scatter charts can be created by plotting abitrary runes onto (X,Y) coordinates.

ntcharts-linechart-scatter (source)
scatter linechart gif

Streaming

Streaming charts display a continuous a line moving across the Canvas from the right side to the left side.

ntcharts-linechart-streaming (source)
streaming linechart gif

Time Series

Time series charts have values on the Y axis and time values on the X axis.

ntcharts-linechart-timeseries (source)
timeseries linechart gif

Rolling Throughput

Two transfer-speed series retain the last minute plus one sample for edge interpolation. TrimBefore bounds storage, and FitYToViewWithOpts fits the visible data with a zero baseline. Watch the Y range shrink when the initial 3.5 GB/s spike leaves the window about ten seconds after startup.

Run go run ./linechart/throughput from the examples directory. (source)

Log Scale

A time series chart can use a logarithmic Y axis (linechart.ScaleLog). Labels fall on powers of ten and equal ratios are equal distances, so data that grows by orders of magnitude stays readable. Press l to switch the same chart between a linear and a log axis, and + / - to zoom the Y axis.

ntcharts-linechart-logscale (source)
log scale linechart gif

Dual Y Axes

A line chart can show a second Y axis on the right with its own range, scale, and labels. Here a load between 0 and 1 (green, left axis) and a temperature between 5 and 20 C (red, right axis) share one time axis. Press + / - to zoom the Y axes; the right axis follows the left one.

ntcharts-linechart-dualaxis (source)
dual Y axes linechart gif

Wave Line

Wave line charts display a continuous a line going across the line chart.

ntcharts-linechart-wavelines (source)
wavelines linechart gif

Sparkline

Sparklines displays data moving across the Canvas from the right side to the left side.

ntcharts-sparkline (source)
sparkline gif

Heatmap

Heatmaps display (x,y) data over a grid with color mapping.

ntcharts-heatmap-simple Simple Heatmap (source)
simple heatmap image

ntcharts-heatmap-aoc2024 AoC 2024.4 Heatmap (source)
heatmap aoc2024 image

ntcharts-heatmap-functor Functors TUI(source)
heatmap functors still heatmap functors still

ntcharts-heatmap-perlin Perlin Noise TUI (source)
heatmap perlin still

ntcharts-heatmap-labels Labelled Heatmap (source)
An index grid drawn as filled cells (heatmap.WithCellSize) with row and column names (WithXLabels / WithYLabels). Press l to drop the labels and - / + to resize; labels that no longer fit are dropped rather than overdrawn.
labelled heatmap gif

Picture

picture displays a Golang image.Image via Glyph (colored block) or full Kitty terminal graphics. pictureurl adds HTTP loading features. (For details on running Kitty graphics inside tmux, see KITTY.md).

The example's source image is a hand-made 1-bit recreation of Hokusai's waves: 01 of 36 views of Mt Fuji by hypertalking

g toggles Glyph ↔ Kitty; f cycles fit mode (Contain → Fill → Cover); q quits.

ntcharts-picture (source)
picture wave image

ntcharts-picture-grid (source)
Composes sprites into a picture.GridImage, then renders that single bitmap with FitFill so logical board coordinates stay aligned with Kitty terminal cells.

ntcharts-picture-simple is a minimal example (source)

Chart Picture

chartpicture displays a github.com/go-analyze/charts chart via an embedded picture.Model. In the example, you may toggle between a random line chart and bar chart. You can toggle between glyph mode and Kitty Graphics mode.

ntcharts-chartpicture (source)
chartpicture animated image

Heat Picture

heatpicture is a continuous-field heatmap rendered through an embedded picture.Model — a Sampler func(x, y float64) float64 is sampled at full terminal-pixel resolution in Kitty mode (smooth gradients, no cell-grid quantization), and at half-block resolution in Glyph mode for fast fallback. Compared to heatmap (which stores sparse data points and renders one solid color per cell), heatpicture is the right fit for function-driven sources where every pixel can be sampled cheaply.

The Perlin demo animates a 2D Perlin-noise field. <space> starts/stops the animation; t toggles Glyph ↔ Kitty; F cycles the sampling factor (1.0 → 0.5 → 0.25) to trade quality for animation smoothness on large terminals; g/i cycle/invert the gradient; a/z, s/x, d/c, f/v adjust α, β, n, and seed. The info bar shows per-frame render time and frame/composite counters.

ntcharts-heatpicture-perlin (source)

Categorical combo

combo-categorical renders profit bars on the left axis and a margin line on the right, with negative values and a missing point. From the repository root, run go run ./examples/combo-categorical; optionally add -html /tmp/combo.html to render the same spec with ECharts. See the combo spec contract.

Documentation

Overview

Package examples includes various examples of using the ntcharts package.

Directories

Path Synopsis
barchart
horizontal command
vertical command
canvas
logo command
examples/chartpicture/main.go
examples/chartpicture/main.go
Command combo-categorical prints a categorical bar/line combo.
Command combo-categorical prints a categorical bar/line combo.
Command combo-timeseries-bar demonstrates ntcharts' multi-surface spec package by building a single chart specification and rendering it to both a terminal and an ECharts HTML file.
Command combo-timeseries-bar demonstrates ntcharts' multi-surface spec package by building a single chart specification and rendering it to both a terminal and an ECharts HTML file.
graph
braille command
candlesticks command
circles command
columns command
lines command
rows command
heatmap
aoc2024 command
functor command
heatcalc command
labels command
Labels shows a heatmap drawn as a grid of filled cells with row and column names: visits by day of the week and time of day.
Labels shows a heatmap drawn as a grid of filled cells with row and column names: visits by day of the week and time of day.
perlin command
simple command
heatpicture
perlin command
linechart
circles command
dualaxis command
Dualaxis shows two series on very different scales sharing one time axis: a load between 0 and 1 on the left Y axis and a temperature between 5 and 20 C on the right Y axis.
Dualaxis shows two series on very different scales sharing one time axis: a load between 0 and 1 on the left Y axis and a temperature between 5 and 20 C on the right Y axis.
lines command
logscale command
Logscale shows a timeseries linechart on a logarithmic Y axis.
Logscale shows a timeseries linechart on a logarithmic Y axis.
scatter command
streaming command
throughput command
Throughput keeps one minute of transfer speeds and fits Y to that window.
Throughput keeps one minute of transfer speeds and fits Y to that window.
timeseries command
wavelines command
Command ohlc-volume renders one OHLCV spec in the terminal and optionally HTML.
Command ohlc-volume renders one OHLCV spec in the terminal and optionally HTML.
examples/picture/main.go
examples/picture/main.go
grid command
simple command
examples/picture/simple/main.go
examples/picture/simple/main.go
Quickstart is a tutorial creating a simple timeserieslinechart that uses keyboard and mouse for zooming in and out, and moving the chart right and left.
Quickstart is a tutorial creating a simple timeserieslinechart that uses keyboard and mouse for zooming in and out, and moving the chart right and left.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL