Expand description
§tui-chart
Chart widgets for ratatui.
§Widgets
LineChart– line / step / area / scatter, multi-series, secondary y axisCandlestickChart– candles, Heikin-Ashi, OHLC, volume, indicator panesBarChart– vertical/horizontal, grouped/stackedHistogram,Heatmap,Sparkline,Gauge,RadarChartBoxPlot,Waterfall,Gantt,DepthChart,RenkoChart,TreemapChartStack– stack charts with a shared gutter
§Features
Annotations (lines, regions, labels) and an interactiveCrosshair- 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
themecargo feature:Theme(built-in themes viaTheme::all,Theme::next,Theme::prev); every widget then has.theme(impl Into<Theme>) - high resolution:
Marker(Braille2×4 default,HalfBlock,Block,Dot, opt-inSextant2×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 andOverlapPolicyforCanvascolour conflicts - optional
serdecargo feature:Serialize/Deserializeon data types and (withtheme)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).
- Band
Overlay - 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 includesend). - BoxPlot
- Box-and-whisker chart widget.
- BoxStats
- Five-number summary plus outliers.
- Candle
- One OHLC(V) bar.
- Candlestick
Chart - Candlestick / OHLC chart with optional volume panel and overlays.
- Canvas
- A pixel canvas where each terminal cell holds several dots.
- Chart
Stack - Splits an area into panes sized by ratio weights.
- Crosshair
- A cursor position in data coordinates, drawn as guide lines + tooltip.
- Depth
Chart - 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.
- 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.
- Line
Chart - Multi-series line / step / area / scatter chart with sub-cell resolution.
- Nearest
Point - Result of a nearest-point lookup.
- Overlay
- Technical overlay (e.g. moving average) aligned to the candle index.
- Radar
Chart - Spider chart with N axes and any number of series.
- Radar
Series - One data series of a
RadarChart. - Renko
Brick - A single renko brick.
- Renko
Chart - Renko / point-and-figure chart widget.
- Ring
Buffer - 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
f64samples with monotonically increasing x positions. - Task
- One Gantt task.
- Trade
Marker - A buy/sell marker placed at a candle index and price.
- Treemap
- Squarified treemap widget.
- Treemap
Item - One treemap item. A leaf uses
value; an item with children is sized by the sum of its children. - Waterfall
- Waterfall chart widget.
Enums§
- Annotation
Kind - Geometry of an
Annotationin data coordinates. - BarMode
- How multiple values per group are combined.
- BarOrientation
- Bar direction.
- BoxOrientation
- Direction of the value axis.
- Candle
Style - Visual style of each bar.
- Gauge
Orientation - Direction of a linear gauge.
- Gauge
Style - Visual form of a
Gauge. - Gradient
- Color gradient presets.
- Grid
Style - Look of grid lines.
- Indicator
Pane - Sub-pane drawn below the price (and volume) panel, sharing the x axis.
- Label
Position - Where value labels are placed relative to their bar.
- Legend
Position - Where the legend is drawn inside the plot.
- Line
Mode - How a series is drawn.
- Marker
- Glyph family used to draw plotted points.
- Overlap
Policy - Which colour wins when several dots with different colours share a cell.
- Renko
Style - Rendering style.
- Sparkline
Style - Rendering style of a
Sparkline. - Stack
Direction - Direction in which panes are stacked.
- Trade
Side - 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 andkpopulation 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 ofcivil_from_days).- draw_
annotations - Draw
annotationsinsideplot. - 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 byscale(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 (
Noneuntilperiodvalues 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
spanwith aboutcountticks (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, seetime_ticksfor calendar alignment). - time_
ticks - Tick timestamps within
[min, max], aboutcountof 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).