Baseline
A baseline series uses different line and fill colours above and below a reference. See the series overview for lifecycle and identity.
Data and reference
Section titled “Data and reference”Pass a scalar with
Bar::from_value
or OHLC bars, whose close is the default main-series price source. Set
ChartTypeParams::baseline
to BaselineLevel::Price
for a fixed price, or PercentOfPane for a position measured from the pane bottom.
The default is 50% of pane height, not a 50% price change. With a base price of
108, values 110 and 106 are respectively above and below the base, including on
an inverted price scale.
Style and running result
Section titled “Style and running result”The scene uses the sample history with a fixed 108 base and a separate gradient on each side fading to transparent at the base.
Compare closes on both sides of 108, then pan without moving the reference price.
The interactive example needs JavaScript and WebAssembly. You can still use the chart setup alongside it.
use egui_charts::Chart;
pub fn baseline() -> Chart { use eframe::egui::Color32; use egui_charts::{ChartType, model::BaselineLevel}; let mut chart = crate::first_chart::first_chart(); chart.set_chart_type(ChartType::Baseline); let mut params = chart.chart_type_params().clone(); params.baseline = BaselineLevel::Price(108.0); params.styles.baseline.above_fill_at_base = Some(Color32::TRANSPARENT); params.styles.baseline.below_fill_at_base = Some(Color32::TRANSPARENT); chart.set_chart_type_params(params); chart}The compiled setup is in series.rs.
BaselineStyle
has independent above and below line styles and fill colours. Optional
above_fill_at_base and below_fill_at_base set the gradient endpoints at the
reference; None keeps each fill flat. Gradient endpoints interpolate in screen
space between the pane edge and the base. Curvature follows the above line on
both sides.
Added baseline series always read close and use the default base at 50% of pane
height. Set their full line/fill style through
SeriesOptions::baseline_style.
With None, up_color, down_color and width provide the lines and flat fills.
Added options do not expose a fixed-price base. See the
added-series restrictions before
choosing the main and added renderers.