Skip to main content

Chart

Struct Chart 

Source
pub struct Chart { /* private fields */ }
Expand description

A chart of any ChartKind. Its shapes are drawn into a picture at the screen’s density, and its labels are real text. Over the picture it says what each value is, under the pointer or with the arrow keys. ChartKind::Scatter and the sparklines stay as plain pictures, which take no focus, until given a tooltip.

Available with the charts feature, on by default.

use ravenrs_widgets::{Chart, ChartKind};

let sales = Chart::new(ChartKind::Line)
    .title("Sales")
    .categories(["Jan", "Feb", "Mar"])
    .series("2025", [12.0, 18.0, 15.0])
    .series("2026", [14.0, 21.0, 26.0])
    .height(240.0);

Implementations§

Source§

impl Chart

Source

pub fn new(kind: ChartKind) -> Chart

An empty chart, 220 logical pixels tall, as wide as its parent allows.

Source

pub fn categories( self, categories: impl IntoIterator<Item = impl Into<String>>, ) -> Chart

What each point is about: the labels along the bottom, or of each slice.

Source

pub fn positions(self, positions: impl IntoIterator<Item = f64>) -> Chart

Where each point sits on the horizontal axis of a ChartKind::Scatter.

Source

pub fn series( self, name: impl Into<String>, values: impl IntoIterator<Item = f64>, ) -> Chart

Adds a series in the theme’s next color, with one value per category. Pie and doughnut charts use the first series.

Source

pub fn candles(self, candles: impl IntoIterator<Item = [f64; 4]>) -> Chart

The candles of a ChartKind::Candlestick, one per category, each with its open, high, low and close, in that order. Rising candles are outlines and falling ones are solid, in the theme’s colors for success and danger.

use ravenrs_widgets::{Chart, ChartKind};

let prices = Chart::new(ChartKind::Candlestick)
    .categories(["Mon", "Tue"])
    .candles([[100.0, 112.0, 98.0, 110.0], [110.0, 111.0, 101.0, 102.0]]);
Source

pub fn series_color( self, name: impl Into<String>, color: Color, values: impl IntoIterator<Item = f64>, ) -> Chart

Adds a series in a color of your choosing.

Source

pub fn title(self, title: impl Into<String>) -> Chart

A title above the chart.

Source

pub fn hide_legend(self) -> Chart

Hides the legend, which otherwise appears when there is something to tell apart.

Source

pub fn format(self, format: impl Fn(f64) -> String + 'static) -> Chart

How numbers appear on the axis (at most two decimals by default).

Source

pub fn height(self, height: f32) -> Chart

Height in logical pixels (default 220).

Source

pub fn size(self, width: f32, height: f32) -> Chart

Fixed size in logical pixels, for a sparkline in a row.

Source

pub fn alt(self, text: impl Into<String>) -> Chart

Describes the chart for screen readers, in place of its title. Its values are read after it.

Source

pub fn series_icon(self, name: &str, icon: IconName) -> Chart

Gives the series called name an icon, for the legend and the tooltip.

Source

pub fn curve(self, curve: Curve) -> Chart

How lines go from point to point (natural by default).

Source

pub fn stack(self, stack: Stack) -> Chart

How series share a category: side by side by default, or stacked.

Source

pub fn gradient(self) -> Chart

Fills areas from strong at the top to faint at the bottom, and bars from strong at the tip to fainter at the base.

Source

pub fn fill_opacity(self, opacity: f32) -> Chart

How solid an area or a radar polygon is, from 0 to 1.

Source

pub fn horizontal(self) -> Chart

Bars lie down, with their categories on the left.

Source

pub fn bars_from(self, from: ChartBarFrom) -> Chart

Where bars grow from: up from the bottom by default.

Source

pub fn min_bar_length(self, length: f32) -> Chart

The shortest a bar with a value gets, in logical pixels, however small the value is (half a pixel by default). A value of zero stays as good as nothing.

Source

pub fn labels_at_zero(self) -> Chart

The categories of bars sit on the line of zero, on its other side from the bar, instead of along the edge of the chart: for values both ways from zero.

Source

pub fn bar_radius(self, radius: f32) -> Chart

The corners of bars. In a stack, only its outer corners are round.

Source

pub fn vary_colors(self) -> Chart

Gives each category its own color from the theme’s chart colors.

Source

pub fn item_colors(self, colors: impl IntoIterator<Item = Semantic>) -> Chart

Gives the categories these colors, in order, over those of the series.

Source

pub fn negative_color(self, color: Semantic) -> Chart

The color of bars below zero.

Source

pub fn active(self, index: Option<usize>) -> Chart

Makes one category stand out: a slice comes forward, a bar gets an outline.

Source

pub fn dots(self) -> Chart

Draws a dot on each point of a line or a radar.

Source

pub fn dot_icon(self, icon: IconName) -> Chart

Draws this icon on each point of a line, in place of a dot.

Source

pub fn value_labels(self, at: LabelAt) -> Chart

Writes each value beside the data.

Source

pub fn category_labels(self, at: LabelAt) -> Chart

Writes each category beside the data.

Source

pub fn tick_format(self, format: impl Fn(&str) -> String + 'static) -> Chart

How categories are written on the axis, such as a month’s first letters.

Source

pub fn grid(self, grid: Grid) -> Chart

Which gridlines it has (level lines by default).

Source

pub fn grid_dashed(self) -> Chart

Draws the gridlines in dashes.

Source

pub fn grid_columns(self, columns: usize) -> Chart

Upright gridlines evenly spread into this many columns, instead of one at each category or number.

Source

pub fn value_ticks(self, ticks: usize) -> Chart

About how many steps the value axis has (4 by default). Round numbers decide how many exactly.

Source

pub fn align_axis_ends(self) -> Chart

The first category along the axis starts at its point and the last one ends at its point, so that they line up with the ends of a line or an area. The last one always shows, however many others there is no room for.

Source

pub fn value_domain(self, min: f64, max: f64) -> Chart

The value axis goes exactly from min to max, and what is past them is cut off. Its numbers are the round ones in between. Not for expanded stacks.

Source

pub fn reference_line(self, value: f64) -> Chart

A dashed line across the data at this value. The scale stretches to show it, unless Self::value_domain fixed it.

Source

pub fn reference(self, reference: ChartReference) -> Chart

A dashed line across the data with its own text or color.

Source

pub fn hide_category_axis(self) -> Chart

Leaves out the categories along the axis.

Source

pub fn show_value_axis(self) -> Chart

Writes numbers along the axis, which the tooltip otherwise makes unneeded.

Source

pub fn tight_scale(self) -> Chart

The scale fits the values, instead of starting from zero. Not for bars.

Source

pub fn no_separator(self) -> Chart

Leaves out the gap between slices, through which what is behind the chart shows.

Source

pub fn slice_radii(self, shares: impl IntoIterator<Item = f32>) -> Chart

How far each slice reaches, in order, as a share from 0 to 1 of the room from the hole to the edge. A slice with no number here reaches the edge.

Source

pub fn label_guides(self) -> Chart

Labels asked for outside a pie or a doughnut sit in a column on each side, none over another, each joined to its slice by a line with an elbow. The chart gets smaller to give them the room they need.

Source

pub fn hole(self, share: f32) -> Chart

The hole of a doughnut or of rings, as a share of the radius.

Source

pub fn concentric(self) -> Chart

One ring per series in a pie, instead of only the first series.

Source

pub fn polar_grid(self, grid: PolarGrid) -> Chart

The shape of the grid of a radar or radial chart.

Source

pub fn polar_fill(self) -> Chart

Fills the grid of a radar chart with the first color.

Source

pub fn no_spokes(self) -> Chart

Leaves out the lines from the center of a radar chart.

Source

pub fn rings(self, rings: usize) -> Chart

How many rings the grid of a radar chart has (5 by default).

Source

pub fn lines_only(self) -> Chart

Radar polygons with no fill.

Source

pub fn radius_axis(self) -> Chart

Writes numbers along the radius of a radar chart.

Source

pub fn angles(self, start: f32, sweep: f32) -> Chart

Where the rings of a radial chart start, in degrees clockwise from the top, and how many degrees the largest covers.

Source

pub fn tracks(self) -> Chart

Draws a track behind each ring of a radial chart.

Source

pub fn center_text( self, value: impl Into<String>, caption: impl Into<String>, ) -> Chart

A big number and a caption in the middle of a doughnut or of rings.

Source

pub fn tooltip(self, tooltip: ChartTooltip) -> Chart

What it says about the category under the pointer. A plain tooltip by default, except on a ChartKind::Scatter and a sparkline: with this they also get the cursor, the dots in focus, and the arrow keys.

Source

pub fn hide_tooltip(self) -> Chart

Says nothing under the pointer and takes no keyboard focus.

Source

pub fn no_hover_focus(self) -> Chart

Keeps the chart as it is around the category under the pointer: the other bars and slices do not fade, and no slice comes forward. The tooltip and the cursor stay.

Source

pub fn no_hover_motion(self) -> Chart

The cursor, its dots and the focus go straight from one category to the next, with no glide and no fade, as they do when the system asks for less motion.

Source

pub fn no_appear(self) -> Chart

The data is whole from the first frame, instead of drawing in the first time the chart is painted.

Source

pub fn animate_changes(self) -> Chart

When the data changes to as many series and categories as before, the chart goes from its old shape to the new one: lines and bars rise or fall to their new values, slices turn and grow, and the value axis slides along with them. A change in the middle starts from where the chart is. Under reduced motion it changes at once. For a filter over the same categories; data that scrolls along, as a live feed does, reads better without it.

Source

pub fn appear_key(self, key: impl Hash) -> Chart

Draws the data in again whenever key changes, such as for a new period or another tab. With none, it only draws in the first time the chart is painted.

Source

pub fn legend_at(self, at: ChartLegend) -> Chart

Where the legend goes (under the chart by default).

Trait Implementations§

Source§

impl Clone for Chart

Source§

fn clone(&self) -> Chart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl View for Chart

Source§

fn build(&self, cx: &mut BuildCx<'_>) -> NodeId

Creates this view’s node for the current build.
Source§

fn type_name(&self) -> &'static str

The name the diagnostics panel shows this view’s cost under.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Chart

§

impl !Send for Chart

§

impl !Sync for Chart

§

impl !UnwindSafe for Chart

§

impl Freeze for Chart

§

impl Unpin for Chart

§

impl UnsafeUnpin for Chart

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<V> ViewExt for V
where V: View,

Source§

fn padding(self, padding: impl Into<Insets>) -> Styled<Self>

Adds padding inside the box, in logical pixels.
Source§

fn background(self, fill: impl Into<Fill>) -> Styled<Self>

Paints a background behind the content.
Source§

fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>

Fixes the width and/or height in logical pixels; None keeps the content size.
Source§

fn width(self, width: f32) -> Styled<Self>

Fixes the width in logical pixels.
Source§

fn height(self, height: f32) -> Styled<Self>

Fixes the height in logical pixels.
Source§

fn grow(self, grow: f32) -> Styled<Self>

Takes a share of the free space in the parent stack.
Source§

fn stretch(self) -> Styled<Self>

Stretches across the parent stack’s cross axis.
Source§

fn centered(self) -> Styled<Self>

Centers the content inside the box.
Source§

fn tooltip(self, text: impl Into<String>) -> Tooltip<Self>

Shows text above the view while the pointer is over it; see Tooltip.
Source§

fn opacity(self, opacity: f32) -> Faded<Self>

Draws the view and everything in it at this opacity, from 0.0 to 1.0, easing to it when it changes. Layout and input stay as they are; see Faded.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more