Skip to main content
Each candle encodes four values — open, high, low, close — for a single period. The body spans from open to close (green for bullish, red for bearish). The wicks extend from the body to the high and low values. An optional volume panel can be shown below the price chart.

Constructor

new()

Create a candlestick plot with default settings. Returns: CandlestickPlot Defaults:
  • Candle width 0.7
  • Wick width 1.5
  • Green/red/gray colors
  • No volume panel
  • No legend
use kuva::plot::CandlestickPlot;

let plot = CandlestickPlot::new();

Adding Candles

with_candle()

Append a candle in categorical mode.
label
S: Into<String>
Category label shown on the x-axis tick
open
impl Into<f64>
Opening price
high
impl Into<f64>
Highest price during the period
low
impl Into<f64>
Lowest price during the period
close
impl Into<f64>
Closing price
Returns: Self The candle is placed at its insertion index. Use this when candles are evenly spaced (daily, weekly data).
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.5,  99.2, 105.8)  // open, high, low, close
    .with_candle("Tue", 105.8, 108.0, 104.1, 104.5);

with_candle_at()

Append a candle at an explicit numeric x position.
x
f64
Numeric x position where the candle body is centered
label
S: Into<String>
Label text (not used for axis ticks in numeric mode)
open
impl Into<f64>
Opening price
high
impl Into<f64>
Highest price during the period
low
impl Into<f64>
Lowest price during the period
close
impl Into<f64>
Closing price
Returns: Self The candle body is centred at x on a continuous numeric x-axis. Use this when candles are unevenly spaced — for example quarterly data where x is a fractional year.
let plot = CandlestickPlot::new()
    // x = fractional year; candles spaced 0.25 apart
    .with_candle_at(2023.00, "Q1", 110.0, 118.0, 108.0, 116.0)
    .with_candle_at(2023.25, "Q2", 116.0, 122.0, 114.0, 121.0)
    .with_candle_at(2023.50, "Q3", 121.0, 126.0, 118.5, 119.5)
    .with_candle_width(0.15);

Volume Panel

with_volume()

Attach volume values to existing candles.
volumes
I: IntoIterator<Item = T>
Iterator of volume values. Matched to candles in insertion order. If there are fewer volume values than candles, the remaining candles receive no volume.
Returns: Self The volume data is not rendered until with_volume_panel is also called.
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_candle("Tue", 105.0, 108.0, 104.0, 104.5)
    .with_volume([1_250_000.0, 980_000.0])
    .with_volume_panel();

with_volume_panel()

Enable the volume bar panel below the price chart. Returns: Self The panel occupies the bottom portion of the chart area (default 22%). Requires volume data attached via with_volume. Volume bars are colored to match their candle (green = up, red = down).
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_volume([1_250_000.0])
    .with_volume_panel();

with_volume_ratio()

Set the fraction of the total chart height used by the volume panel.
ratio
f64
Fraction in [0.0, 1.0] (default: 0.22)
Returns: Self For example 0.30 gives the volume panel 30% of the chart height and leaves 70% for the price chart. Has no effect unless with_volume_panel is also called.
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_volume([1_250_000.0])
    .with_volume_panel()
    .with_volume_ratio(0.30);

Styling

with_candle_width()

Set the candle body width as a fraction of the slot between candles.
width
f64
Width in [0.0, 1.0] (default: 0.7)
Returns: Self In categorical mode the slot width is 1.0 (one index unit), so 0.7 gives a body that fills 70% of the available space. In numeric mode (with_candle_at) this value is in data units — set it to be smaller than the spacing between candles.
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_candle_width(0.8);

with_wick_width()

Set the wick stroke width in pixels.
width
f64
Stroke width in pixels (default: 1.5)
Returns: Self
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_wick_width(2.0);

with_color_up()

Set the fill color for bullish candles where close > open.
color
S: Into<String>
CSS color string (default: "rgb(68,170,68)" — green)
Returns: Self
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.0, 99.0, 105.0)
    .with_color_up("limegreen");

with_color_down()

Set the fill color for bearish candles where close < open.
color
S: Into<String>
CSS color string (default: "rgb(204,68,68)" — red)
Returns: Self
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 95.0, 94.0, 96.0)
    .with_color_down("darkred");

with_color_doji()

Set the fill color for doji candles where close == open.
color
S: Into<String>
CSS color string (default: "#888888" — gray)
Returns: Self A doji typically signals indecision in the market.
let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 105.0, 98.0, 100.0)  // doji: open == close
    .with_color_doji("silver");

Legend

with_legend()

Add a legend label, causing a legend box to appear inside the plot area.
label
S: Into<String>
Legend label text
Returns: Self
let plot = CandlestickPlot::new()
    .with_candle("Jan", 100.0, 108.0, 98.0, 106.0)
    .with_legend("ACME Corp");

Complete Example

use kuva::plot::CandlestickPlot;
use kuva::backend::svg::SvgBackend;
use kuva::render::render::render_multiple;
use kuva::render::layout::Layout;
use kuva::render::plots::Plot;

let plot = CandlestickPlot::new()
    .with_candle("Mon", 100.0, 106.5,  99.2, 105.8)
    .with_candle("Tue", 105.8, 108.0, 104.1, 104.5)
    .with_candle("Wed", 104.5, 109.2, 104.0, 108.0)
    .with_candle("Thu", 108.0, 111.5, 107.3, 110.9)
    .with_candle("Fri", 110.9, 111.0, 107.8, 108.5)
    .with_legend("ACME");

let plots = vec![Plot::Candlestick(plot)];
let layout = Layout::auto_from_plots(&plots)
    .with_title("Weekly OHLC")
    .with_x_label("Day")
    .with_y_label("Price (USD)");

let svg = SvgBackend.render_scene(&render_multiple(plots, layout));
std::fs::write("candlestick.svg", svg).unwrap();

Public Fields

candles
Vec<CandleDataPoint>
All candles in insertion order
candle_width
f64
Candle body width as a fraction of the slot width between candles (default: 0.7; range 0.0–1.0)
wick_width
f64
Wick stroke width in pixels (default: 1.5)
color_up
String
Fill color for bullish candles (close > open). Default: "rgb(68,170,68)" (green)
color_down
String
Fill color for bearish candles (close < open). Default: "rgb(204,68,68)" (red)
color_doji
String
Fill color for doji candles (close == open). Default: "#888888" (gray)
show_volume
bool
Whether to render the volume bar panel below the price chart
volume_ratio
f64
Fraction of the total chart height reserved for the volume panel (default: 0.22)
legend_label
Option<String>
Optional legend entry label

Build docs developers (and LLMs) love