Skip to content

Price and volume

Price and volume have different units. Keep candles on the price pane and add a column series on a separate pane. This makes the volume scale independent while both panes share the time axis and crosshair.

Apply this setup to the first chart once. It returns the volume series’ stable SeriesId for later updates. Each column’s scalar is explicitly copied from the source bar’s volume into Bar::from_value; column renderers use close, not the volume field.

Candles over an independent volume paneOpen full size

Move the pointer between price and volume. The lower pane reports volume units without stretching the price scale.

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

price_volume.rs
pub fn price_volume(chart: &mut egui_charts::Chart) -> egui_charts::widget::SeriesId {
use eframe::egui::Color32;
use egui_charts::{
ChartType,
model::Bar,
widget::{SeriesId, SeriesOptions},
};
chart.config_mut().show_volume = false;
let volume = chart.add_series(SeriesOptions {
name: "Volume".into(),
chart_type: ChartType::Columns,
up_color: Color32::from_rgb(126, 87, 194),
down_color: Color32::from_rgb(126, 87, 194),
columns_base: Some(0.0),
..Default::default()
});
let values = chart
.bars(SeriesId::MAIN)
.iter()
.map(|bar| Bar::from_value(bar.time, bar.volume))
.collect();
chart.set_data(volume, values);
let pane = chart.add_pane();
chart.move_series_to_pane(volume, pane);
volume
}

show_volume = false disables the built-in volume band so it is not drawn twice. add_pane and move_series_to_pane give the added series its own scale. columns_base: Some(0.0) includes zero in the added series’ autoscale. The scene uses a single colour for both rising and falling volumes; set per-bar colours if you want to colour by price direction.

For each incoming price bar, call update on the main series and update the saved volume id with Bar::from_value(bar.time, bar.volume). A matching timestamp replaces the forming column; a later timestamp appends one. Send the complete accumulated bar volume, not just the latest trade’s quantity. Replace both histories when the instrument or interval changes.

If the built-in volume band already meets your needs, keep it enabled and omit the extra series. See panes for height and separator options, and historical and streaming data for the host feed contract.