Skip to content

Interaction and events

Create the chart once and call Chart::show on every frame. The widget handles chart gestures; your host handles application actions and reads notifications after show. Try the host readout recipe for a running event consumer.

InputDefault chart action
Move over a plotInspect the nearest time slot with the crosshair and readouts
Drag the plot with the primary buttonPan the view
Vertical mouse wheelZoom the time scale around the pointer
Horizontal wheel or Shift+wheelScroll the time scale
Drag the time or price axisChange that axis’ scale
Double-click the time axisReturn to the latest bars
Double-click a price axisRestore autoscale
Touch drag or pinchPan or zoom when the corresponding handler is enabled
Hold a touch still on a plotShow the crosshair and readouts after half a second; they follow the finger and stay until the next tap. With the long press order option, ask for a limit order on the price pane instead

Wheel input over a price axis scales prices instead. Configure ChartOptions::handle_scroll and handle_scale by cloning chart_options, editing the copy and applying it with set_chart_options. Their group enabled switches preserve the individual gesture choices. A touch shows values only once it has been held for TooltipOptions::long_press_delay, and crosshair notifications report it from then on. touch_long_press turns this off, and touch_exit_mode ends the values on release instead of at the next tap. long_press_order makes a hold on the price pane ask for a limit order at the touched price, which ChartMenus::show returns where its menu offers one. Mouse hover is unaffected. TrackingModeOptions controls when following the live edge ends. Active drawing tools can consume plot gestures for placing and editing their points.

Pointer notifications retain egui button or touch input in ChartPointer::origin, including event-time position and modifiers, and touch identity, phase and pressure when supplied by the integration. State-driven updates have no origin. Hosts that know a device is a pen can call set_pointer_kind before show; None restores egui’s mouse/touch detection.

Click a chart or enter it with Tab. Tab and Shift+Tab leave it for the next or previous focusable host control. Shortcuts apply to the focused chart while editable text and dialogs keep their own input. Left and Right pan, command/control plus Up or Down zooms, Home moves to the first bar and End returns to the live edge. Escape cancels the current interaction. The accessibility guide covers focus and native versus canvas accessibility.

ShortcutMap contains editable key bindings. Read or replace them with shortcuts and shortcuts_mut. Drain take_shortcut_requests separately for host commands such as opening symbol search or saving an image. Those requests are not chart events.

ChartLayout::set_shortcuts gives one map to every chart of a layout, and UserSettings::shortcuts keeps it between sessions. With editable set, the keyboard shortcuts dialog lets the user rebind keys and returns the new map. The host handles KeyboardShortcutsAction::Apply by assigning the map to its layout and settings. Change replaces the action’s keys with the next combination; a conflict names its current action and asks before moving it. Clear removes all keys of an action, Escape cancels a capture, and Reset restores the library defaults. Save returns the edited map; Cancel discards it. The edit mode leaves pointer gestures and the fixed typing, drawing-arrow and replay controls unchanged.

Maps save combinations in precedence order using English key names, with Ctrl for the command key (Cmd on Mac). An unknown key or action is skipped on restore; an older settings document without a map keeps defaults, while an empty saved map keeps every action unbound. A saved map keeps its full list until edited or reset, including when a later release adds default bindings.

set_crosshair_mode selects CrosshairMode: Normal snaps time to a slot and follows the pointer’s value; Magnet snaps to nearby visible OHLC, study or added-series values; MagnetClose prefers visible closes on price panes. Appearance is independent: CrosshairStyle::Hidden hides lines and axis tags while readouts still follow the pointer.

set_crosshair_position places a cursor using UTC time and raw price. For multiple charts, forward UTC time with set_synced_crosshair_time; programmatic synchronized cursors do not emit local pointer moves. See the synchronization recipe for range forwarding and clearing cursors on exit.

After show, iterate drain_events in one host dispatcher. It removes pending notifications. Forward each event to the host components that need it; repeated drains do not broadcast it again. The complete readout scene demonstrates this order and a wildcard arm for the non-exhaustive ChartEvent enum.

NotificationHost use
CrosshairMoved(Some(pointer)) / CrosshairMoved(None)Update or clear a host legend or tooltip
Click, DoubleClick, MarkClickRoute the button, position or host marker id to an action
VisibleRangeChanged, VisibleLogicalRangeChanged, TimeScaleResizedObserve UTC edges, slot ranges and layout size
DataLoaded, DataUpdatedRefresh host state after accepted history or changed bars
SeriesAdded, SeriesRemovedStart or stop the host producer for that stable series id
Drawing { id, kind }Follow each drawing the user, undo or redo, or host code created, removed, hid, showed, moved or edited, for example in a host drawing list
Study { id, kind }Follow each study added, removed, hidden, shown or given other inputs by the user, undo or redo, or host code, for example in a host study list
SymbolChanged, TimeframeChangedUpdate host controls for the chart’s instrument and interval
EventsDropped(count)Resynchronize the host from current chart state

The queue retains 1,024 notifications. If the host falls behind, the oldest are dropped and the next drain starts with EventsDropped. Compact data events can coalesce; they are not an audit log. Opt in to set_data_operation_notifications for a separate DataOperation event for each accepted direct set_data or update, including unchanged input. That opt-in does not report feed replies.

ChartPointer carries screen coordinates, pane identity and value even on an empty plot. Its time is the optional timestamp of a stored slot, including whitespace; it is absent outside loaded history. Its main bar can be missing or whitespace, and added-series entries require a matching timestamp. Keep those cases absent in the UI. Study plots have stable ids and optional values. Hidden study values can be included with CursorDataPolicy without changing what the chart paints or autoscales.

Use the annotation recipe for host marker ids and the host contracts for the full payload and formatting rules. The recipe index links the complete integrations.