Skip to main content

Crate tui_chart

Crate tui_chart 

Source
Expand description

§tui-chart

Chart widgets for ratatui.

§Widgets

§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);

Modules§

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

Structs§

Annotation
A reference line, shaded band or text label drawn over a plot.
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).
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.
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.
Funnel
Funnel chart widget: centered bars whose width follows the value.
FunnelStage
One funnel stage.
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).
Histogram
Histogram widget.
LineChart
Multi-series line / step / area / scatter chart with sub-cell resolution.
NearestPoint
Result of a nearest-point lookup.
Overlay
Technical overlay (e.g. moving average) aligned to the candle index.
RadarChart
Spider chart with N axes and any number of series.
RadarSeries
One data series of a RadarChart.
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.
Series
One named data series of (x, y) points.
Sparkline
Compact trend chart, one column per data point (newest points kept when too wide).
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.
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.
GaugeOrientation
Direction of a linear gauge.
GaugeStyle
Visual form of a Gauge.
Gradient
Color gradient presets.
GridStyle
Look of grid lines.
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.
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.

Functions§

atr
Average True Range (Wilder smoothing).
bollinger
Bollinger bands over closes: (middle, upper, lower) using the SMA and k population standard deviations.
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.
ema
Exponential moving average of closes.
heikin_ashi
Convert candles to Heikin-Ashi candles.
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.
renko_bricks
Compute renko bricks from closes with a fixed brick size.
rsi
Relative Strength Index (Wilder smoothing), 0‥100.
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.
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).