Skip to main content

Crate tui_chart

Crate tui_chart 

Source
Expand description

§tui-chart

Chart widgets for ratatui.

§Widgets

§Accessibility

Wrap any chart in Monochrome (or Monochrome::auto, which honours NO_COLOR) to render without colour: solid fills turn into ░▒▓█ shades.

§Features

  • Annotations (lines, regions, labels) and an interactive Crosshair
  • log scale (y_log), spline smoothing, error bars and bands
  • indicators: sma, ema, bollinger, rsi, macd, atr, stochastic, vwap
  • streaming with RingBuffer / Stream
  • time axis helpers (time_ticks, time_hm, date_ymd, …)
  • optional theme cargo feature: Theme (built-in themes via Theme::all, Theme::next, Theme::prev); every widget then has .theme(impl Into<Theme>)
  • high resolution: Marker (Braille 2×4 default, HalfBlock, Block, Dot, opt-in Sextant 2×3 which needs a font with the Unicode “Symbols for Legacy Computing” block), CandleStyle::Braille, .marker(..) on line/bar/sparkline/radar/gauge/histogram/depth/waterfall charts and OverlapPolicy for Canvas colour conflicts
  • optional serde cargo feature: Serialize/Deserialize on data types and (with theme) Theme

All widgets implement ratatui::widgets::Widget (both owned and by reference) and are drawn straight into the buffer.

use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tui_chart::{Axis, LineChart, Series, Theme};

let chart = LineChart::new(vec![Series::new("sin").data(
    (0..50).map(|i| (i as f64, (i as f64 / 5.0).sin())),
)])
.theme(Theme::nord())
.x_axis(Axis::new().title("t"))
.y_axis(Axis::new().grid(true));

let area = Rect::new(0, 0, 60, 15);
let mut buf = Buffer::empty(area);
chart.render(area, &mut buf);
use ratatui::{buffer::Buffer, layout::Rect, widgets::Widget};
use tui_chart::{Candle, CandlestickChart, sma, Overlay};
use ratatui::style::Color;

let candles = vec![
    Candle::new(10.0, 12.0, 9.0, 11.0).volume(1200.0).label("Mon"),
    Candle::new(11.0, 13.0, 10.5, 10.8).volume(900.0).label("Tue"),
];
let avg = sma(&candles, 2);
let chart = CandlestickChart::new(candles)
    .show_volume(true)
    .overlay(Overlay::new("SMA2", avg, Color::Yellow));
let area = Rect::new(0, 0, 40, 16);
let mut buf = Buffer::empty(area);
chart.render(area, &mut buf);

Re-exports§

pub use tui_piechart as piechart;

Modules§

util
Numeric helpers: “nice” tick generation and number formatting.

Structs§

Annotation
A reference line, shaded band or text label drawn over a plot.
AreaLayer
One layer of a StackedAreaChart.
Axis
Configuration for a chart axis (title, bounds, ticks, grid, labels).
BandOverlay
Shaded band between two series (e.g. Bollinger bands) aligned to the candle index.
BarChart
Bar chart widget.
BarGroup
A labelled group of bars (one value per series).
Bin
One histogram bin [start, end) (last bin includes end).
Blip
A contact on a RadarScope.
BoxPlot
Box-and-whisker chart widget.
BoxStats
Five-number summary plus outliers.
BubbleChart
Bubble chart widget. Bubble area is proportional to size.
BubbleSeries
A named set of (x, y, size) points.
Bullet
Bullet chart widget (one row per item, shared scale 0..max).
BulletItem
One bullet row.
CalendarHeatmap
Calendar heatmap widget: consecutive daily values starting at start_day.
Candle
One OHLC(V) bar.
CandlestickChart
Candlestick / OHLC chart with optional volume panel and overlays.
Canvas
A pixel canvas where each terminal cell holds several dots.
ChartStack
Splits an area into panes sized by ratio weights.
Crosshair
A cursor position in data coordinates, drawn as guide lines + tooltip.
DepthChart
Order-book depth chart. Bids are drawn as a cumulative step-area on the left, asks on the right, with a mid-price marker and spread readout.
DotMatrix
LED dot matrix: one column of dots per value (0..=1), lit from the bottom.
Funnel
Funnel chart widget: centered bars whose width follows the value.
FunnelStage
One funnel stage.
Fx
Wraps a widget and applies post effects after it renders.
Gantt
Gantt chart widget.
Gauge
Gauge showing a value inside [min, max].
HLine
Horizontal reference line (support / resistance / target…).
Heatmap
Heatmap widget (rows × columns of values).
HexMap
Honeycomb heat map: cols hexes per row, each colored by its value (0..=1).
Histogram
Histogram widget.
Hit
A rectangle of cells that a chart element occupies.
HitMap
The hit regions of one rendered frame.
Interaction
Pointer state: hover position, selection and hidden series.
LineChart
Multi-series line / step / area / scatter chart with sub-cell resolution.
LollipopChart
Lollipop / dumbbell chart widget.
LollipopItem
One row of a LollipopChart.
Monochrome
Renders the wrapped widget, then removes its colours (see the module docs).
NearestPoint
Result of a nearest-point lookup.
Oscilloscope
Phosphor-style trace over a divided graticule. Samples are -1..=1.
Overlay
Technical overlay (e.g. moving average) aligned to the candle index.
PairedBars
PairedBars chart widget: for every measure two bars on one scale 0..max(before, after), so the scales may differ between measures (mixed units work). An optional legend names the two series.
PairedBarsItem
One measure: a value before and a value after.
Pie
A PieChart that reports hover / click regions and supports hiding slices (see Interaction).
PieChart
A widget that displays a pie chart.
PieSlice
A slice of the pie chart representing a portion of data.
RadarChart
Spider chart with N axes and any number of series.
RadarScope
Radar screen: range rings, a rotating beam with a fading wedge and blips that light up as the beam passes.
RadarSeries
One data series of a RadarChart.
RadialBar
Concentric progress rings, outermost first, with an optional legend.
RadialRing
One ring of a RadialBar.
RenkoBrick
A single renko brick.
RenkoChart
Renko / point-and-figure chart widget.
RingBuffer
Fixed-capacity FIFO ring buffer; pushing past capacity drops the oldest item.
RingStack
Concentric 270° rings, one per (label, percent), with a legend.
RoseChart
Rose chart widget.
RoseItem
One sector of a RoseChart.
Sankey
Sankey diagram widget. Nodes are created from the link endpoints and laid out left to right by their longest path from a source.
SankeyLink
A flow from one node to another.
Series
One named data series of (x, y) points.
SlopeChart
Slope chart widget.
SlopeItem
One line of a SlopeChart.
Sparkline
Compact trend chart, one column per data point (newest points kept when too wide).
Spectrum
Equalizer bars (0..=1) built from segments with zone colors and peak caps.
StackedAreaChart
Stacked area chart widget.
Stream
A rolling window of f64 samples with monotonically increasing x positions.
Task
One Gantt task.
TradeMarker
A buy/sell marker placed at a candle index and price.
Treemap
Squarified treemap widget.
TreemapItem
One treemap item. A leaf uses value; an item with children is sized by the sum of its children.
View
Zoom / pan state for the x axis: a window lo..hi of the full 0..=1 span.
ViolinChart
Violin plot widget.
ViolinGroup
One violin: a label and its samples.
Waterfall
Waterfall chart widget.

Enums§

AnnotationKind
Geometry of an Annotation in data coordinates.
BarMode
How multiple values per group are combined.
BarOrientation
Bar direction.
BoxOrientation
Direction of the value axis.
CandleStyle
Visual style of each bar.
Click
What a click did.
GaugeOrientation
Direction of a linear gauge.
GaugeStyle
Visual form of a Gauge.
Gradient
Color gradient presets.
GridStyle
Look of grid lines.
HitKind
What a Hit describes.
IndicatorPane
Sub-pane drawn below the price (and volume) panel, sharing the x axis.
LabelPosition
Where value labels are placed relative to their bar.
LegendPosition
Where the legend is drawn inside the plot.
LineMode
How a series is drawn.
Marker
Glyph family used to draw plotted points.
OverlapPolicy
Which colour wins when several dots with different colours share a cell.
PairedBarsLayout
How the two bars of a measure sit.
RadialSweep
Sweep of a RadialBar.
RenkoStyle
Rendering style.
SparklineStyle
Rendering style of a Sparkline.
StackDirection
Direction in which panes are stacked.
TradeSide
Side of a TradeMarker.

Constants§

PALETTE
Default series color cycle.

Traits§

FxExt
.glow(..) / .scanlines(..) on any widget, so effects read like any other builder call:

Functions§

atr
Average True Range (Wilder smoothing).
blip_alpha
Brightness 0..=1 of a radar blip at turn-fraction blip while the sweep is at sweep: full as the beam passes, fading over one revolution.
bollinger
Bollinger bands over closes: (middle, upper, lower) using the SMA and k population standard deviations.
bracket_block
A frame with heavy corner brackets and light sides, like a HUD readout.
chamfer_block
A frame with cut (chamfered) corners and a title.
civil_from_days
Days since 1970-01-01 → (year, month 1..=12, day 1..=31).
date_md
Format as MM-DD (UTC).
date_ymd
Format as YYYY-MM-DD (UTC).
datetime
Format as YYYY-MM-DD HH:MM:SS (UTC).
days_from_civil
(year, month, day) → days since 1970-01-01 (inverse of civil_from_days).
draw_annotations
Draw annotations inside plot.
ecg_beat
One heartbeat-shaped period (-1..=1) for x in 0..1: P wave, QRS spike, T wave.
ema
Exponential moving average of closes.
glow
Spread each lit cell’s color into the background of nearby empty cells.
heikin_ashi
Convert candles to Heikin-Ashi candles.
hex_center
Centre of hex (row, col) for a pointy-top grid with circumradius s.
hex_extent
Grid size (width, height) of rows × cols hexes of circumradius s.
jitter
Animated bar value: v modulated by a per-bar sine at time t.
macd
MACD: (macd line, signal line, histogram).
nearest_point
Index and distance of the point closest to target, with each axis divided by scale (so distances are comparable). Non-finite points are skipped.
no_color_requested
true when the NO_COLOR environment variable is set to a non-empty value.
renko_bricks
Compute renko bricks from closes with a fixed brick size.
rsi
Relative Strength Index (Wilder smoothing), 0‥100.
scanlines
Darken every other row (strength 0..=1), like a CRT scanline mask.
shared_gutter
Shared gutter width for x-aligned panes: the widest of the given label widths.
sma
Simple moving average of closes (None until period values exist).
stochastic
Stochastic oscillator: (%K, %D) where %D is the SMA of %K.
strip_color
Strip colour from area of buf, replacing solid fills by shade glyphs.
time_hm
Format as HH:MM (UTC).
time_hms
Format as HH:MM:SS (UTC).
time_nice_step
A nice time-aware step in seconds for covering span with about count ticks (1 s, 5 s, 1 min, 1 h, 1 day, 1 week, … up to 30 days; beyond that month/year steps are returned as 30.44-day multiples, see time_ticks for calendar alignment).
time_ticks
Tick timestamps within [min, max], about count of them. Sub-month steps align to multiples of the step (days align to UTC midnight); month/year steps align to calendar month/year starts.
vwap
Cumulative volume-weighted average price (typical price × volume).