Skip to content

Price lines and markers

Use a price line for a level in a series’ units and a marker for an annotation attached to a stored timestamp. They belong to the addressed bar series, including an added series in another pane.

Pass the first chart to this setup once before the frame loop. It marks the newest bar and draws a reference two price units below its close. Empty history is allowed and leaves the chart unchanged.

A reference level and a bar annotationOpen full size

Hover the newest bar's arrow to read its tooltip. Pan and zoom: the annotation stays attached to its time.

The interactive example needs JavaScript and WebAssembly. You can still use the chart setup alongside it.

annotations.rs
pub fn annotations(chart: &mut egui_charts::Chart) {
use eframe::egui::Color32;
use egui_charts::{
model::{Marker, MarkerPos, MarkerShape, PriceLine},
widget::SeriesId,
};
let Some(last) = chart.bars(SeriesId::MAIN).last() else {
return;
};
let (time, close) = (last.time, last.close);
let color = Color32::from_rgb(126, 87, 194);
chart.set_price_lines(
SeriesId::MAIN,
vec![PriceLine::new(close - 2.0, color).with_title("Reference")],
);
chart.set_markers(
SeriesId::MAIN,
vec![
Marker::new(time)
.with_pos(MarkerPos::BelowBar)
.with_shape(MarkerShape::ArrowUp)
.with_color(color)
.with_text("Signal")
.with_tooltip("Host annotation at the latest bar")
.with_id("latest-signal"),
],
);
}

set_markers replaces the complete marker list for the series; pass an empty vector to clear it. Marker times match data points. Use MarkerPos to place a shape above or below its bar, or at an explicit price. The default MarkerOptions::auto_scale reserves space for visible price-relative markers and labels.

add_price_line returns an optional PriceLineId. Retain it to call update_price_line or remove_price_line. The setup does not need individual edits, so it uses set_price_lines to replace all levels. That replacement invalidates earlier line handles.

A marker with an id emits ChartEvent::MarkClick on a primary click. Drain events after showing the chart and route that id to your host action. Hovering a marker or a price line sets ChartPointer::target to PointerTarget::Marker or PointerTarget::PriceLine, which carry the series and the marker id or line handle. Remove an annotation by replacing the marker list without it. Interactive drawing tools and their persistence are covered by the drawing guide.