Skip to content

Theming

Both ChartView and ChartView expose a set_theme method that controls every color in the chart — background, candles, grid, text, crosshair, and the default plot color palette.

Built-in Themes

Two presets are provided out of the box:

rust
use navi_chart::Theme;

let dark  = Theme::dark();   // dark background, pastel accents
let light = Theme::light();  // white background, vivid accents

Apply one right after construction:

rust
cv.set_theme(Theme::dark());

The chart re-renders immediately whenever set_theme is called.

Fully Custom Theme

Construct a Theme struct literal to set every color explicitly:

rust
use navi_chart::{Theme, Stroke, LineStyle};
use navi_types::Color;

cv.set_theme(Theme {
    bg:                   Color::from_rgb(18, 18, 18),
    surface:              Color::from_rgb(30, 30, 30),
    grid:                 Color::from_rgba(255, 255, 255, 26),
    text:                 Color::from_rgb(220, 220, 220),
    text_dim:             Color::from_rgb(120, 120, 120),
    bull:                 Color::from_rgb(0, 200, 100),
    bear:                 Color::from_rgb(220, 50, 50),
    crosshair_line:       Color::from_rgba(200, 200, 200, 100),
    bull_text:            Color::from_rgb(0, 200, 100),
    bear_text:            Color::from_rgb(220, 50, 50),
    highlight:            Color::from_rgba(255, 255, 255, 200),
    legend_bg:            Color::from_rgba(18, 18, 18, 204),
    selection_handle:     Color::from_rgb(100, 160, 255),
    selection_handle_bg:  Color::from_rgb(255, 255, 255),
    last_price_line: Stroke {
        color: Color::from_rgba(120, 120, 140, 180),
        width: 1.0,
        style: LineStyle::Dashed,
    },
    plot_colors: [
        Color::from_rgb(100, 160, 255),
        Color::from_rgb(255, 200, 80),
        Color::from_rgb(180, 120, 240),
        Color::from_rgb(80, 210, 180),
        Color::from_rgb(255, 140, 80),
        Color::from_rgb(240, 100, 180),
        Color::from_rgb(150, 160, 255),
        Color::from_rgb(100, 210, 130),
    ],
});

Or start from a preset and adjust individual fields:

rust
let mut theme = Theme::dark();
theme.bull = Color::from_rgb(0, 230, 118);
theme.bear = Color::from_rgb(255, 82, 82);
cv.set_theme(theme);

Theme Field Reference

FieldTypeDescription
bgColorCanvas / chart background
surfaceColorSurface color (labels, separators)
gridColorGrid line color
textColorPrimary text color
text_dimColorDimmed / secondary text color
bullColorBullish (up) candle body color
bearColorBearish (down) candle body color
crosshair_lineColorCrosshair line color
bull_textColorBullish OHLC value text color
bear_textColorBearish OHLC value text color
highlightColorHighlighted (selected) bar border color
legend_bgColorSemi-transparent background for legend / label text rows
selection_handleColorStroke (border) color for selection handle dots on selected annotations, plots, and other chart elements
selection_handle_bgColorFill (background) color for selection handle dots
last_price_lineStrokeStyle (color, width, dash) for the horizontal line and right-axis label drawn at the last bar's close price. Visibility is controlled separately via set_last_price_line_visible.
plot_colors[Color; 8]Default plot color palette (cycled when a script doesn't specify a color)

Color encoding: Color is a packed u32 in RGBA format. Use Color::from_rgb(r, g, b) for opaque colors and Color::from_rgba(r, g, b, a) for colors with transparency (alpha 0 = fully transparent, 255 = fully opaque).

Released under the MIT License.