ntcharts

module
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT

README

ntcharts - Nimble Terminal Charts

Build Status Latest Release GoDoc Code Of Conduct

ntcharts is a Golang Terminal Charting library for the Bubble Tea Framework and other TUIs.

We supply many chart types within the glory of your terminal!

Type Description
Canvas A 2D grid to plot arbitrary runes, with LipGloss for styling and BubbleZone for mousing. It is the foundation for all the following charts.
Bar Chart Displays values as either horizontal rows or vertical columns.
Heat Map Displays (x,y) values on a color-mapped heatmap.
Line Chart Displays (X,Y) data points onto a 2D grid in various types of charts.
OHLC/Candle Chart Displays Open, High, Low, Close values as candlesticks.
Picture Displays images with picture and via http with pictureurl
Chart Picture Renders go-analyze/charts chart images via an embedded picture.Model — Kitty graphics with glyph fallback.
Scatter Chart Plots abitrary runes onto (X,Y) coordinates.
Streamline Chart Displays a continuous a line moving across the Canvas from the right side to the left side.
Time Series Chart Displays lines with values on the Y axis and time values on the X axis.
Waveline Chart A line chart that connects points in a wave pattern.
Sparkline A small, simple visual of data chart for quick understanding.

Quickstart Tutorial

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.

quickstart gif

Demo Apps

Standalone CLI demos. Run task to build them all into the bin/ directory.

Command Source What it shows
ntcharts-quickstart examples/quickstart The tutorial above — time-series chart with two data sets, mouse support.
ntcharts-ohlc cmd/ntcharts-ohlc Renders OHLC candles + a sparkline from a CSV (example.csv) using the time-series line chart with braille runes.
ntcharts-lorem-picsum cmd/ntcharts-lorem-picsum Sortable/filterable Lorem Picsum catalog browser; previews the selected image side-by-side in Glyph and Kitty graphics modes via pictureurl. Requires a Kitty-graphics-capable terminal for the right pane.
ntcharts-picture examples/picture Two-pane image demo: embedded PNG via picture on the left, fetched URL via pictureurl on the right.
ntcharts-chartpicture examples/chartpicture Live-updating chart rendered through chartpicture (go-analyze/charts → image → Kitty/Glyph). Press r to swap line/bar, t to cycle themes, g to toggle modes.

ntcharts-lorem-picsum gif

ntcharts-ohlc gif

BubbleTea Version Compatibility

We have migrated to Bubble Tea v2. It exists on the v2 branch. You should import as so:

import "github.com/NimbleMarkets/ntcharts/v2"

Our Bubble Tea v1 compatible library exists on the main branch. You should import it as so:

import "github.com/NimbleMarkets/ntcharts"

We will continue to backport relevant fixes to both branches.

Please note that the v2 designation is for BubbleTea API compatibility. Despite the version number, the ntcharts API is still subject to change. v2 is the primary development branch branch now.

Usage

See the examples folder for code samples and visuals of each type.

Canvas
package main

import (
    "fmt"
    "github.com/NimbleMarkets/ntcharts/v2/canvas"
    "charm.land/lipgloss/v2"
)

func main() {
    c := canvas.New(5, 2)
    c.SetLinesWithStyle(
        []string{"hello", "world"},
        lipgloss.NewStyle().Foreground(lipgloss.Color("6"))) // cyan

    fmt.Println(c.View())
}

This example produces the following canvas with Lip Gloss foreground color:

canvas png
Bar Chart
package main

import (
    "fmt"
    "github.com/NimbleMarkets/ntcharts/v2/barchart"
    "charm.land/lipgloss/v2"
)

func main() {
    d1 := barchart.BarData{
        Label: "A",
        Values: []barchart.BarValue{
            {"Item1", 21.2, lipgloss.NewStyle().Foreground(lipgloss.Color("10"))}}, // green
    }
    d2 := barchart.BarData{
        Label: "B",
        Values: []barchart.BarValue{
            {"Item1", 15.2, lipgloss.NewStyle().Foreground(lipgloss.Color("9"))}}, // red
    }

    bc := barchart.New(11, 10)
    bc.PushAll([]barchart.BarData{d1, d2})
    bc.Draw()

    fmt.Println(bc.View())
}

This example produces the following bar chart with green and red bars:

barchart png
Streamline Chart
package main

import (
    "fmt"
    "github.com/NimbleMarkets/ntcharts/v2/linechart/streamlinechart"
)

func main() {
    slc := streamlinechart.New(13, 10)
    for _, v := range []float64{4, 6, 8, 10, 8, 6, 4, 2, 0, 2, 4} {
        slc.Push(v)
    }
    slc.Draw()

    fmt.Println(slc.View())
}

This example produces the following streamline chart:

  │  ╭╮      
 8│  ││      
  │ ╭╯╰╮     
 6│ │  │     
  │╭╯  ╰╮    
 4├╯    ╰╮  ╭
  │      │  │
 2│      ╰╮╭╯
  │       ││ 
 0│       ╰╯ 
Time Series Chart
package main

import (
    "fmt"
    "time"
    "github.com/NimbleMarkets/ntcharts/v2/linechart/timeserieslinechart"
)

func main() {
    tslc := timeserieslinechart.New(41, 10)
    for i, v := range []float64{0, 4, 8, 10, 8, 4, 0, -4, -8, -10, -8, -4, 0} {
        date := time.Now().Add(time.Hour * time.Duration(24*i))
        tslc.Push(timeserieslinechart.TimePoint{date, v})
    }
    tslc.DrawBraille()

    fmt.Println(tslc.View())
}

This example produces the following time series chart using braille runes starting with today's date:

 10│      ⣀⠤⠒⠉⠒⠤⡀                        
   │    ⡠⠊      ⠈⠢⡀                      
  5│  ⡠⠊          ⠈⠢⡀                    
   │⡠⠊              ⠈⠑⢄                 ⢀
  0│                   ⠑⡄              ⡔⠁
   │                    ⠈⠢⡀          ⡠⠊  
 -5│                      ⠈⠢⡀      ⡠⠊    
   │                        ⠈⠑⠢⢄⡠⠔⠊      
-10└─────────────────────────────────────
   '24 03/27   03/31   04/03   04/05     
Waveline Chart
package main

import (
    "fmt"
    "github.com/NimbleMarkets/ntcharts/v2/canvas"
    "github.com/NimbleMarkets/ntcharts/v2/linechart/wavelinechart"
)

func main() {
    wlc := wavelinechart.New(12, 10, wavelinechart.WithYRange(-3, 3))
    wlc.Plot(canvas.Float64Point{1.0, 2.0})
    wlc.Plot(canvas.Float64Point{3.0, -2.0})
    wlc.Plot(canvas.Float64Point{5.0, 2.0})
    wlc.Plot(canvas.Float64Point{7.0, -2.0})
    wlc.Plot(canvas.Float64Point{9.0, 2.0})
    wlc.Draw()

    fmt.Println(wlc.View())
}

This example produces the following waveline chart:

 3│         
  │╭╮  ╭╮  ╭
 2│││  ││  │
  │││  ││  │
 0├╯╰╮╭╯╰╮╭╯
  │  ││  ││ 
-2│  ││  ││ 
  │  ╰╯  ╰╯ 
-3└─────────
  0 2 4 6    
Sparkline
package main

import (
    "fmt"
    "github.com/NimbleMarkets/ntcharts/v2/sparkline"
)

func main() {
    sl := sparkline.New(10, 5)
    sl.PushAll([]float64{7.81, 3.82, 8.39, 2.06, 4.19, 4.34, 6.83, 2.51, 9.21, 1.3})
    sl.Draw()

    fmt.Println(sl.View())
}

This example produces the following sparkline:

sparkline png
Heat Map

Heat Maps map values to colors on a 2D grid. The following example creates a heatmap of the function sin(sqrt(x^2 + y^2)). There are more examples in the examples README.

package main

import (
	"fmt"
	"math"

	"github.com/NimbleMarkets/ntcharts/v2/heatmap"
)

func main() {
	hm := heatmap.New(20, 20, heatmap.WithValueRange(0, 1))
	hm.SetXYRange(-1, 1, -1, 1)
	for x := float64(-1); x < 1.0; x += 1.0 / float64(hm.GraphWidth()) {
		for y := float64(-1); y < 1.0; y += 1.0 / float64(hm.GraphHeight()) {
			val := math.Sin(math.Sqrt(x*x + y*y))
			hm.Push(heatmap.NewHeatPoint(x, y, val))
		}
	}
	hm.Draw()
	fmt.Println(hm.View())
}

This example (source) produces the following heatmap:

simple heatmap png

Open Collaboration

We welcome contributions and feedback. Please adhere to our Code of Conduct when engaging our community.

Acknowledgements

Thanks to Charm.sh for making the command line glamorous and sharing Bubble Tea and Lip Gloss and more. Thanks to BubbleZone for bringing the mouse support 🐭.

Thanks also to asciigraph, ratatui, and termdash for inspiration.

License

Released under the MIT License, see LICENSE.txt.

The image [`./examples/picture/Fuji-01.png] is from this link and licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Copyright (c) 2024-2026 Neomantra Corp.


Made with ❤ and 🔥 by the team behind Nimble.Markets.

Directories

Path Synopsis
Package barchart implements a canvas that displays a bar chart with bars going either horizontally or vertically.
Package barchart implements a canvas that displays a bar chart with bars going either horizontally or vertically.
Package canvas implements an abstract 2D area used to plot arbitary runes that can be displayed using the bubbletea framework.
Package canvas implements an abstract 2D area used to plot arbitary runes that can be displayed using the bubbletea framework.
buffer
Package buffer contain buffers used with charts.
Package buffer contain buffers used with charts.
graph
Package graph contains data structures and functions to help draw runes on to a canvas.
Package graph contains data structures and functions to help draw runes on to a canvas.
runes
Package runes contains commonly used runes and functions to obtain runes.
Package runes contains commonly used runes and functions to obtain runes.
cmd
ntcharts-lorem-picsum command
examples/picture/main.go
examples/picture/main.go
ntcharts-ohlc command
Displays OHLC data as a line chart from an input CSV file.
Displays OHLC data as a line chart from an input CSV file.
Package examples includes various examples of using the ntcharts package.
Package examples includes various examples of using the ntcharts package.
canvas/logo command
chartpicture command
examples/chartpicture/main.go
examples/chartpicture/main.go
graph/braille command
graph/circles command
graph/columns command
graph/lines command
graph/rows command
heatmap/aoc2024 command
heatmap/functor command
heatmap/perlin command
heatmap/simple command
linechart/lines command
picture command
examples/picture/main.go
examples/picture/main.go
quickstart command
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.
sparkline command
Package heatmap implements a canvas that displays a heatmap, color-mapped data over a grid.
Package heatmap implements a canvas that displays a heatmap, color-mapped data over a grid.
Package linechart implements a canvas that displays (X,Y) Cartesian coordinates as a line chart.
Package linechart implements a canvas that displays (X,Y) Cartesian coordinates as a line chart.
streamlinechart
Package streamlinechart implements a linechart that draws lines going from the right of the chart to the left of the chart
Package streamlinechart implements a linechart that draws lines going from the right of the chart to the left of the chart
timeserieslinechart
Package timeserieslinechart implements a linechart that draws lines for time series data points
Package timeserieslinechart implements a linechart that draws lines for time series data points
wavelinechart
Package wavelinechart implements a linechart that draws wave lines on the graph
Package wavelinechart implements a linechart that draws wave lines on the graph
chartpicture
Package chartpicture is a go-analyze/charts source for picture.Model.
Package chartpicture is a go-analyze/charts source for picture.Model.
pictureurl
Package pictureurl is a URL-driven layer on top of picture.Model.
Package pictureurl is a URL-driven layer on top of picture.Model.
Package sparkline implements a canvas that displays time series data as a chart with columns moving from right to left.
Package sparkline implements a canvas that displays time series data as a chart with columns moving from right to left.

Jump to

Keyboard shortcuts

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