Skip to main content

Crate egui_charts

Crate egui_charts 

Source
Expand description

Interactive financial charts for egui, using your historical and streaming data.

Chart provides price and volume panes, pan and zoom, crosshairs and live bar updates on native and WebAssembly targets. Optional features add built-in studies, drawing tools, order flow visualizations and application UI such as toolbars, replay controls, trading panels and dialogs. The host supplies market data, external accounts and durable storage through the crate’s contracts.

§Quick start

Enable widget for a chart without application UI or built-in studies:

egui-charts = { git = "https://github.com/userFRM/egui-charts", branch = "main", default-features = false, features = ["widget"] }

Create the chart once with bars ordered from oldest to newest, then call Chart::show in your egui UI callback each frame:

use egui_charts::{Chart, model::{Bar, BarData}};

let bars = vec![
    Bar::new("2024-01-01T00:00:00Z".parse().unwrap(),
             100.0, 102.0, 99.0, 101.0, 1_000.0),
    Bar::new("2024-01-01T00:01:00Z".parse().unwrap(),
             101.0, 103.0, 100.0, 102.0, 1_200.0),
];
let mut chart = Chart::new(BarData::from_bars(bars));

chart.show(ui);

For live data, merge bars with Chart::update(widget::SeriesId::MAIN, bar). data::Datafeed supports paged history and streaming bars, trades and depth; attach a feed with ChartBuilder::with_feed. Feed methods return promptly, answer requests through data::Reply and push updates through data::Sink. A symbol identifies the host’s instrument; setting it does not fetch data without a feed. See the guide for complete integration examples.

§API map

ModuleUse it for
widgetChart, ChartBuilder, events, panes, chart layouts, replay and export
modelBars, instruments, intervals, chart types, price transforms and host data records
dataHistorical and streaming data contracts, aggregation and order flow data
studiesThe Indicator extension point, calculation helpers and built-in studies
drawingsDrawing tools, selection, undo and timestamp-based persistence
scalesPrice ranges, coordinate mapping, axis ticks and label formatting
configChart appearance and interaction options
servicesHost storage, symbol search, quotes, alerts, signals and broker contracts
strategiesStrategies that trade on closed bars and the backtest engine that runs them
theme, tokens, stylesTheme presets, design tokens and UI styling helpers
ui, ui_kitChart controls and reusable UI components placed in the host’s layout
iconsEmbedded SVG icons
localizationHost translations scoped to an egui context
preludeCommon types and traits for chart integration

§Feature flags

The defaults are ui, locales, timezones, csv and png-export. With default-features = false, the data model, scales, feed and service contracts, tokens and study extension points are available without an egui dependency.

FeatureDefaultEnables
widgetvia uiThe chart widget, rendering, configuration, themes, styling and localization
drawingsvia uiDrawing tools, interaction, undo and persistence; enables widget
studiesvia uiBuilt-in studies, IndicatorFactory and study templates; usable without egui
alert-engineoffservices::AlertEngine, an Alerts service that evaluates alerts on the bars the host feeds it; needs no egui
detectorsoffservices::OrderFlowDetectors, a Signals service that finds order-flow events in the trades and depth the host feeds it; needs no egui
strategiesoffstrategies::Backtest, which runs a Strategy over bars and returns a StrategyReport; needs no egui
iconsvia uiEmbedded SVG icons and their pixel-aligned loader; enables widget
uionToolbars, panels, dialogs and ui_kit; enables icons, studies, drawings, csv and png-export
localesonLocalized month and weekday names and AM/PM markers through chrono; otherwise English
timezonesonIANA zones and daylight-saving rules through chrono-tz; otherwise UTC, system local time and fixed offsets
csvonCSV import/export for bars, strategy reports and chart data; enabled by ui
png-exportonCPU PNG export and image textures embedded in SVG export; enables widget, enabled by ui
serdeoffSerialize and Deserialize for theme::Theme

Without default features, enable csv to use CSV methods; JSON I/O stays available. Enable png-export for PNG methods and textured SVG output. Without it, SVG exports text and vector geometry and returns ExportError::Unsupported for image textures; renderer frames from Chart::export_image remain available. With icons alone, the chart installs only its embedded icon loader. General SVG images require ui or an image loader installed by the host.

§Application integration

Keep a chart across frames so its viewport, studies and drawings persist. Application UI components return actions for the host to apply. The crate does not connect to a market data provider on its own.

Apply theme::apply_to_egui at startup and after changing the theme. It installs the bundled font and applies UI colors and spacing. Use localization::set_translator for UI text; the host owns translation resources and additional fonts. Chart date and number labels use the chart’s formatters.

The guide covers historical and streaming data, custom studies, drawing persistence, synchronized charts and host strategy and script results.

§API compatibility

The 0.3 release line uses egui 0.37. Use a compatible egui version in your host so types such as egui::Ui agree across the dependency graph. Before 1.0, breaking API changes require a minor release; afterward they require a major release. An incompatible upgrade of exposed egui types is a breaking change.

Construct extensible options with their constructors or Default, then assign public fields. Include a fallback arm when matching a #[non_exhaustive] enum.

Re-exports§

pub use model::ChartType;
pub use widget::Chart;
pub use widget::ChartBuilder;
pub use widget::RightClickTarget;

Modules§

chart
Rendering and geometry helpers for chart composition.
config
Appearance and interaction options for the chart widget.
data
Historical and streaming market data contracts, aggregation and order flow data.
drawings
Drawing tools and annotations anchored to chart coordinates.
guide
Builder guide
icons
Embedded SVG icons for chart controls and host UI.
localization
Host-supplied UI translations, scoped to an egui context.
model
Data types for bars, instruments, chart styles, trading and host analytics.
prelude
Common types and extension traits for embedding a chart.
scales
Price ranges, coordinate transforms, axis ticks and label formatting.
services
Services a host supplies, each through a small trait. Charts consume Marks, Signals and Posts and keep their drawings in Storage, symbol choosers consume SymbolSearch, the alerts panel Alerts, the watchlist Quotes, the notifications panel Notifications and the chats panel Chats. SettingsStore and the layout menu keep settings and layouts in Storage; other contracts define the host side of the assembled terminal. PaperAccount is a ready-made Broker that simulates an account, and AlertEngine, with the alert-engine feature, an Alerts service that evaluates alerts on the bars the host feeds it. OrderFlowDetectors, with the detectors feature, is a Signals service that finds order-flow events in the trades and depth the host feeds it.
strategies
Strategies over historical and live bars, and the Backtest engine that runs them.
studies
Technical indicators, calculation helpers and study presentation.
styles
UI sizing, typography, icon sizes and keyboard focus helpers.
theme
Theme: the colours and scales of the UI and the chart.
tokens
Design tokens: default spacing, sizing, rounding, stroke, shadow and engine colour values. UI chrome reads the applied theme.
ui
Chart toolbars, panels, dialogs and trading controls for host applications.
ui_kit
Reusable UI components for building chart interfaces.
widget
Interactive charts, events, panes, layouts and export.

Macros§

icon_from_path
Macro to embed an SVG icon at compile time.