Skip to content

Add a second series

Continue from your first chart. Keep its candles and add a line from another host-supplied sequence. A series has its own identity, data, style and scale assignment; adding it does not fetch a symbol’s history.

Call this setup once with your existing chart and keep the returned SeriesId. The synthetic reference is exactly one price unit above each main close, so sharing the right price scale is appropriate here.

Candles with a host-fed reference lineOpen full size

Hover the line and candles to compare their values. The reference is one unit above each stored close.

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

second_series.rs
pub fn second_series(chart: &mut egui_charts::Chart) -> egui_charts::widget::SeriesId {
use eframe::egui::Color32;
use egui_charts::{
model::Bar,
widget::{SeriesId, SeriesOptions},
};
let reference = chart.add_series(SeriesOptions {
name: "Reference (+1)".into(),
color: Color32::from_rgb(126, 87, 194),
..Default::default()
});
let values = chart
.bars(SeriesId::MAIN)
.iter()
.map(|bar| Bar::from_value(bar.time, bar.close + 1.0))
.collect();
chart.set_data(reference, values);
reference
}

add_series returns the handle. SeriesOptions names and styles the added series; the default renderer is a line. set_data loads its history and Bar::from_value stores each scalar at its timestamp. In the shared sample, slot 10 closes at 101.8, so the line there is 101.8 + 1.0 = 102.8. Real comparison data comes from your own historical and streaming source.

Keep the id beside the chart. Send the complete latest scalar with update(id, bar): the same timestamp replaces a value and a later one appends. Updating SeriesId::MAIN does not update added series automatically. Preserve missing observations with whitespace.

set_series_visible hides a series while retaining its data and id. remove_series removes it; stop its host subscription when it leaves the chart. Keep host data available if your UI supports undo restoring that id. The interaction guide describes series lifecycle notifications.

For unrelated units, assign an independent scale or use the price and volume recipe to place a second series in another pane. Continue with host readouts to read both series at the cursor, or browse the series lifecycle.