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
impl ChartBuilder
Sourcepub fn new() -> Self
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.
Sourcepub fn options_chart() -> Self
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.
Sourcepub fn price_chart() -> Self
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.
Sourcepub fn with_feed(self, feed: Arc<dyn Datafeed>) -> Self
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.
Sourcepub fn with_symbol(self, symbol: impl Into<String>) -> Self
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.
Sourcepub fn with_timeframe(self, timeframe: Timeframe) -> Self
pub fn with_timeframe(self, timeframe: Timeframe) -> Self
Set the bar aggregation timeframe (default: Timeframe::Min1).
Sourcepub fn with_theme(self, theme: Theme) -> Self
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.
Sourcepub fn with_chart_type(self, chart_type: ChartType) -> Self
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.
Sourcepub fn with_config(self, config: ChartConfig) -> Self
pub fn with_config(self, config: ChartConfig) -> Self
Override the entire ChartConfig (axis visibility, grid, realtime button, etc.).
Sourcepub fn with_chart_options(self, options: ChartOptions) -> Self
pub fn with_chart_options(self, options: ChartOptions) -> Self
Override the ChartOptions (crosshair, time scale, scroll/zoom behavior, etc.).
Sourcepub fn with_session_breaks(self, show: bool) -> Self
pub fn with_session_breaks(self, show: bool) -> Self
Toggle session-break dividers (day/week/month boundaries) and shading.
Sourcepub fn with_indicators(self, registry: IndicatorRegistry) -> Self
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.
Sourcepub fn with_drawing_registry(self, registry: DrawingToolRegistry) -> Self
pub fn with_drawing_registry(self, registry: DrawingToolRegistry) -> Self
Set host drawing tools and built-in availability before the chart is built.
Sourcepub fn with_locale(self, locale: impl Into<String>) -> Self
pub fn with_locale(self, locale: impl Into<String>) -> Self
Name months and weekdays in locale’s language, as Chart::set_locale does.
Sourcepub fn with_time_formatter(self, formatter: Arc<dyn TimeFormatter>) -> Self
pub fn with_time_formatter(self, formatter: Arc<dyn TimeFormatter>) -> Self
Format time labels, as Chart::set_time_formatter does.
Sourcepub fn with_price_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self
pub fn with_price_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self
Format price labels, as Chart::set_price_formatter does.
Sourcepub fn with_percentage_formatter(
self,
formatter: Arc<dyn PriceFormatter>,
) -> Self
pub fn with_percentage_formatter( self, formatter: Arc<dyn PriceFormatter>, ) -> Self
Format percentage and indexed price labels, as Chart::set_percentage_formatter does.
Sourcepub fn with_volume_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self
pub fn with_volume_formatter(self, formatter: Arc<dyn PriceFormatter>) -> Self
Format volumes, as Chart::set_volume_formatter does.
Sourcepub fn with_storage(self, storage: Arc<dyn Storage>) -> Self
pub fn with_storage(self, storage: Arc<dyn Storage>) -> Self
Keep the drawings of each symbol in storage, as Chart::set_storage does.
Sourcepub fn with_study_factory(self, factory: IndicatorFactory) -> Self
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.
Sourcepub fn with_visible_candles(self, count: usize) -> Self
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.
Sourcepub fn with_initial_bars(self, bars: usize) -> Self
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();Sourcepub fn with_right_price_scale(self, visible: bool, mode: PriceScaleMode) -> Self
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();Sourcepub fn with_realtime_btn(self, visible: bool) -> Self
pub fn with_realtime_btn(self, visible: bool) -> Self
Enable or disable the scroll-to-latest button.
Default: true (visible)
Set the position of the scroll-to-latest button.
Default: BottomRight
Set custom text for the scroll-to-latest button. Set its size to fit the text.
Default: a double right chevron
Set the size of the scroll-to-latest button (width, height) in points.
Default: (28.0, 28.0)
Sourcepub fn build(self) -> Chart
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.
Sourcepub fn build_restored(
self,
snapshot: &ChartSnapshot,
) -> Result<(Chart, Vec<SkippedDrawing>), RestoreError>
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§
Auto Trait Implementations§
impl !RefUnwindSafe for ChartBuilder
impl !Sync for ChartBuilder
impl !UnwindSafe for ChartBuilder
impl Freeze for ChartBuilder
impl Send for ChartBuilder
impl Unpin for ChartBuilder
impl UnsafeUnpin for ChartBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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