Skip to main content

ChartBuilder

Struct ChartBuilder 

Source
pub struct ChartBuilder { /* private fields */ }
Expand description

Fluent builder for a Chart.

Use one of the constructor methods (new, price_chart, options_chart) and chain configuration calls before calling build to produce the chart.

All setter methods return Self and are marked #[must_use] to prevent accidental drops of the builder mid-chain.

§Examples

use egui_charts::{ChartBuilder, ChartType};
use egui_charts::model::Timeframe;
use egui_charts::theme::Theme;

let chart = ChartBuilder::new()
    .with_symbol("ETHUSDT")
    .with_timeframe(Timeframe::Hour1)
    .with_theme(Theme::dark())
    .with_chart_type(ChartType::Candles)
    .with_visible_candles(120)
    .build();

Implementations§

Source§

impl ChartBuilder

Source

pub fn new() -> Self

Create a new chart builder with sensible defaults

With a feed and a symbol, the chart asks for the latest 1000 bars at its first show, and again when the symbol or timeframe changes.

Source

pub fn options_chart() -> Self

Creates a line chart with the time axis labels and ticks hidden.

The data is still a time series of bars, and pan and zoom work as on any chart.

§Examples
use egui_charts::ChartBuilder;

// Line chart without time axis labels
let chart = ChartBuilder::options_chart()
    .with_symbol("SPY")
    .build();
§Note

For traditional OHLC price charts, use ChartBuilder::new() instead.

Source

pub fn price_chart() -> Self

Creates a line chart without grid or crosshair, showing 50 bars.

Drawing tools and studies are not added.

§Examples
use egui_charts::ChartBuilder;

// Create minimal price ticker
let chart = ChartBuilder::price_chart()
    .with_symbol("BTCUSDT")
    .with_visible_candles(30)  // Even narrower view
    .build();

// Clean chart with no grid, crosshair, or tools
§Dashboard Example
use egui_charts::ChartBuilder;

// Multiple mini-charts for dashboard
let btc_chart = ChartBuilder::price_chart()
    .with_symbol("BTCUSDT")
    .build();

let eth_chart = ChartBuilder::price_chart()
    .with_symbol("ETHUSDT")
    .build();
§Note

For drawing tools and studies, use ChartBuilder::new() instead.

Source

pub fn with_feed(self, feed: Arc<dyn Datafeed>) -> Self

Source of instrument, history and live updates. Without one, feed the chart with Chart::set_data and Chart::update.

build calls no feed method: with a symbol, the chart’s first show asks the feed for the instrument and the latest page of history, and subscribes once the instrument resolves.

Source

pub fn with_symbol(self, symbol: impl Into<String>) -> Self

Set the trading symbol (e.g., "BTCUSDT", "AAPL").

Without a symbol the chart shows none and requests nothing from the feed.

Source

pub fn with_timeframe(self, timeframe: Timeframe) -> Self

Set the bar aggregation timeframe (default: Timeframe::Min1).

Source

pub fn with_theme(self, theme: Theme) -> Self

Set a per-chart theme. Without one the chart follows the active egui theme.

Applies colours to the ChartConfig and retains a per-chart override for text sizes, axes, legends and overlays. It leaves egui and sibling charts unchanged. Use Chart::set_theme_override to replace or clear it on a persistent chart.

Source

pub fn with_chart_type(self, chart_type: ChartType) -> Self

Set the chart visualization type (default: ChartType::Candles).

Common types: Candles, Line, Area, Bar, Baseline, Histogram.

Source

pub fn with_config(self, config: ChartConfig) -> Self

Override the entire ChartConfig (axis visibility, grid, realtime button, etc.).

Source

pub fn with_chart_options(self, options: ChartOptions) -> Self

Override the ChartOptions (crosshair, time scale, scroll/zoom behavior, etc.).

Source

pub fn with_session_breaks(self, show: bool) -> Self

Toggle session-break dividers (day/week/month boundaries) and shading.

Source

pub fn with_indicators(self, registry: IndicatorRegistry) -> Self

Add the studies of registry (SMA, RSI, MACD, etc.) to the chart, which computes, updates and draws them.

Source

pub fn with_drawing_registry(self, registry: DrawingToolRegistry) -> Self

Set host drawing tools and built-in availability before the chart is built.

Source

pub fn with_locale(self, locale: impl Into<String>) -> Self

Name months and weekdays in locale’s language, as Chart::set_locale does.

Source

pub fn with_time_formatter(self, formatter: Arc<dyn TimeFormatter>) -> Self

Format time labels, as Chart::set_time_formatter does.

Source

pub fn with_price_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self

Format price labels, as Chart::set_price_formatter does.

Source

pub fn with_percentage_formatter( self, formatter: Arc<dyn PriceFormatter>, ) -> Self

Format percentage and indexed price labels, as Chart::set_percentage_formatter does.

Source

pub fn with_volume_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self

Format volumes, as Chart::set_volume_formatter does.

Source

pub fn with_storage(self, storage: Arc<dyn Storage>) -> Self

Keep the drawings of each symbol in storage, as Chart::set_storage does.

Source

pub fn with_study_factory(self, factory: IndicatorFactory) -> Self

Build the studies of a saved chart passed to build_restored through factory, so that studies it registers are restored. Without one only the built-in studies are.

Source

pub fn with_visible_candles(self, count: usize) -> Self

Set the number of bars visible in the initial viewport (default: 100).

This controls the initial bar spacing so that approximately count bars fit within the chart width. Use zero to keep the configured bar spacing.

Source

pub fn with_initial_bars(self, bars: usize) -> Self

Bars asked for in the first page of history (default 1,000); scroll-back pages ask for at least 600.

§Examples
use egui_charts::ChartBuilder;

let chart = ChartBuilder::new().with_initial_bars(500).build();
Source

pub fn with_right_price_scale(self, visible: bool, mode: PriceScaleMode) -> Self

Configure the right price scale

The right price scale is the primary scale, shown by default. The chart starts with this visibility and scale mode.

§Examples
use egui_charts::ChartBuilder;
use egui_charts::scales::PriceScaleMode;

let chart = ChartBuilder::new()
    .with_right_price_scale(true, PriceScaleMode::Logarithmic)
    .build();
Source

pub fn with_realtime_btn(self, visible: bool) -> Self

Enable or disable the scroll-to-latest button.

Default: true (visible)

Source

pub fn with_realtime_button_pos(self, position: RealtimeButtonPos) -> Self

Set the position of the scroll-to-latest button.

Default: BottomRight

Source

pub fn with_realtime_button_text(self, text: impl Into<String>) -> Self

Set custom text for the scroll-to-latest button. Set its size to fit the text.

Default: a double right chevron

Source

pub fn with_realtime_button_size(self, width: f32, height: f32) -> Self

Set the size of the scroll-to-latest button (width, height) in points.

Default: (28.0, 28.0)

Source

pub fn build(self) -> Chart

Consume the builder and produce the chart.

This applies the theme to the config and sets up the chart. It never blocks and calls no feed method: with a feed and a symbol, the chart’s first show asks the feed for the instrument and history.

Source

pub fn build_restored( self, snapshot: &ChartSnapshot, ) -> Result<(Chart, Vec<SkippedDrawing>), RestoreError>

Consume the builder and show the saved chart snapshot on the new chart.

The chart is built as by build with the locale, formatters, storage, feed and studies of the builder, and snapshot is then restored with with_study_factory’s factory, as Chart::restore_with does, before the chart is returned. The host then binds data to the restored series with Chart::restored_series_id. Returns the drawings that could not be read with the chart. A snapshot that cannot be restored is an error and no chart.

Trait Implementations§

Source§

impl Default for ChartBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.