Skip to content

Configuration ​

Everything that is not data lives in a PlotConfig you can keep in your model and edit in a dialog. The screen and the SVG/PNG export use the same config.

Live demo
The starter gallery, live: open “Chart settings…” or a chart's gear to edit every PlotConfig field; the arrow exports SVG/PNG.Open in a tab ↗
rust
use egui_workbench::components::plot::{Plot, PlotConfig};

let mut config = PlotConfig::default();
config.title = Some("Signal".to_owned());
config.x.label = Some("t (s)".to_owned());
config.y.label = Some("V".to_owned());
config.legend_size = 12.0;

let plot = Plot::new("signal").config(config.clone()).series(Series::line("sin", &data));

Plot::config(cfg) replaces the whole appearance. Builder methods such as .title(...) and .x_scale(...) edit the config afterwards, so call .config first.

Text and sizes ​

FieldDefaultControls
titleNoneTitle above the data area
x.label, y.label, y2.labelNoneAxis titles
title_size14.0Title points
title_colorNoneTitle color; colors.text or the theme when None
title_alignCenterTitleAlign::{Left, Center, Right} over the data area
label_size12.0Axis title points (each axis can override it)
tick_size11.0Tick label points
legend_size11.5Legend points

Axes ​

Each axis is an AxisConfig: x, y (left), and y2 (right; shown when a series uses YAxis::Right, grid off by default):

FieldDefaultControls
labelNoneAxis title
scaleLinearLinear or Log10
min, maxNoneFixed limits; None is automatic
major_stepNoneMajor spacing; 1-2-5 when None
minorAutoAuto, Off, or Divisions(n)
grid_majortrueGrid at major ticks
grid_minortrueGrid at minor ticks
decimalsNoneTick label decimals
tick_labelstrueDraw labels
label_sizeNoneThis axis title's points; PlotConfig::label_size when None
label_colorNoneThis axis title's color
tick_colorNoneTick labels and marks (color the right axis like its series)

Plot::x_limits(min, max), y_limits, and y2_limits are shorthands for the limits; y2_label and y2_scale set up the right axis.

Lines and chrome ​

FieldDefaultControls
frame_width1.0Frame stroke
grid_width1.0Grid stroke
grid_major_opacity0.55Major grid alpha
grid_minor_opacity0.22Minor grid alpha
tick_length4.0Major tick length outside the frame
line_scale1.0Multiplies every line width
marker_scale1.0Multiplies every marker size
legendTopLeftTopLeft, BottomLeft, BottomRight, Hidden
legend_frametrueLegend background
toolbartrueTool buttons
hover_guidestrueDashed guides to the axes
hover_popuptrueHover popup
legend_hoverBlink, linear, 1.2 sLegend row animation: enabled, animation, easing, period, highlight
directionoff, 5 samplesDirection arrow: enabled, points, length, width, head, color
piepieinner_radius, start_angle, labels, percentages, total
radar4 ringslabels, max, rings, fill_opacity
gauge270° arcstart_angle, end_angle, thickness, show_value, show_range
heatmapopaqueopacity, colorbar
waterfallconnectors onbar_width, connectors

Colors ​

PlotColors holds optional overrides; None follows the theme:

FieldColors
backgroundData area fill
canvasArea around the data frame (transparent on screen by default)
frameFrame and tick marks
gridGrid lines (before opacity)
textTitle and axis titles
tick_textTick labels
selectionSelection fill and outline
rust
config.colors.background = Some(theme.sunken);
config.colors.grid = Some(theme.border);
config.colors.selection = Some(theme.accent);

Per-series styles ​

rust
let style = config.series_style_mut("signal");
style.color = Some(theme.success);
style.width = Some(2.0);
style.line_style = Some(LineStyle::Dashed);
style.marker = Some(Marker::Ring);
style.marker_size = Some(4.0);
style.fill_opacity = Some(0.2);
style.smoothing = Some(Smoothing::Spline);
style.y_axis = Some(YAxis::Right);

series_style(name) reads without creating; series_style_mut(name) creates an empty override when missing. Styles are matched by series name; SeriesStyle::is_empty() tells a dialog which overrides it can drop.

Sanitize ​

Call config.sanitize() after editing in a dialog:

  • font sizes, widths, opacities, and lengths are clamped;
  • an inverted limit pair drops max;
  • log axes drop non-positive limits;
  • major_step must be finite and positive;
  • Minor::Divisions is clamped to 2–20;
  • decimals are capped at 10;
  • series widths, marker sizes, fill opacities, and direction switches are clamped;
  • the legend animation period, direction samples/sizes, pie radius, radar rings, gauge thickness/angles, heatmap opacity, and waterfall width are clamped.

If limits or scales changed, call PlotState::reset_view().

Settings dialog pattern ​

The template's Charts section keeps a PlotConfig per tab, edits a copy in a dialog, and applies it on close:

rust
if self.chart_settings_open {
    let mut open = self.chart_settings_open;
    let mut config = self.chart_config.clone();
    Dialog::new("chart-settings", "Chart settings", &mut open).width(520.0).show(ctx, |ui| {
        settings_section(ui, "Text", "Titles and sizes.");
        settings_row(ui, "Title", "Shown above the data area.", |ui| {
            TextField::new(config.title.get_or_insert_default()).width(ui.available_width()).show(ui);
        });
        settings_row(ui, "X label", "Axis title.", |ui| {
            TextField::new(config.x.label.get_or_insert_default()).width(ui.available_width()).show(ui);
        });
        // ... axis, grid, colors, series
    });
    if !open {
        config.sanitize();
        self.chart_config = config;
        self.plot_state.reset_view();
    }
    self.chart_settings_open = open;
}

The starter has the complete dialog with tabs for text, axes, grid, colors, each series, and Motion (legend animation and direction arrow). See templates/app/src/chart_settings/.

Export uses the same config ​

to_svg and to_png take the PlotConfig inside the Plot and the PlotState view. Build the plot once:

rust
fn build_plot<'a>(data: &'a [[f64; 2]], config: &PlotConfig) -> Plot<'a> {
    Plot::new("report")
        .config(config.clone())
        .series(Series::line("signal", data))
}

let plot = build_plot(&self.data, &self.config);
let response = plot.clone().show(ui, &mut icons, &mut state);

Then export plot.to_svg(ctx, &state, &options). See Export.

Plot3D has its own Plot3DConfig with x/y/z AxisConfigs, Surface3DConfig, a Projection, and Series3DStyle overrides. The text sizes, colors, legend, hover, and direction fields match PlotConfig; see 3D charts.

Released under MIT OR Apache-2.0. Icons: Lucide (ISC) and Material Icon Theme (MIT).