Skip to content

Histogram and columns

Use columns for one scalar per timestamp, such as volume, counts or a signed measurement. The bar-series renderer is named ChartType::Columns; there is no ChartType::Histogram. Computed study plots have a separate PlotType::Histogram. See the series overview for bar-series lifecycle and studies for computed plots.

Use Bar::from_value(time, value). The column height uses close, not the volume field. To plot volume, explicitly map each source bar’s volume into the scalar, as this scene does. Negative scalar values are valid; negative bar volume is not.

The default base is the pane bottom. For columns rising or falling from zero, set ChartTypeParams::columns_base to Some(0.0). Values 3 and -2 then extend three units above and two below zero. The default colours compare each close with the previous close, not with zero. Set per-bar colours if sign should decide.

This scene turns the volume of the shared synthetic bars into scalar values and sets an explicit zero base. It fixes the price range at 0 to 1,500 with PriceScale::set_range so zero is visible. Main-series autoscale fits the values without including the column base; added column series include their base in the fit.

Volume values as columns from zeroOpen full size

Inspect the scalar values: these are source volumes copied into close.

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

series_histogram.rs
use egui_charts::Chart;
pub fn histogram() -> Chart {
use egui_charts::{ChartType, model::Bar, widget::SeriesId};
let mut chart = crate::first_chart::first_chart();
let values = chart
.bars(SeriesId::MAIN)
.iter()
.map(|bar| Bar::from_value(bar.time, bar.volume))
.collect();
chart.set_data(SeriesId::MAIN, values);
chart.set_chart_type(ChartType::Columns);
chart.config_mut().show_volume = false;
chart.config_mut().show_legend_volume = false;
let mut params = chart.chart_type_params().clone();
params.columns_base = Some(0.0);
chart.set_chart_type_params(params);
chart.price_scale_mut().set_range(0.0, 1_500.0);
chart
}

The compiled setup is in series.rs. Main columns use the bullish/bearish colours in ChartConfig. Added columns use SeriesOptions::up_color, down_color and columns_base. BarColors::color overrides an individual column. Width follows bar spacing.

Columns can be added series. Use a separate scale or pane for volume beside prices; see Chart::move_series_to_pane and scales.