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
impl Chart
Sourcepub fn new(kind: ChartKind) -> Chart
pub fn new(kind: ChartKind) -> Chart
An empty chart, 220 logical pixels tall, as wide as its parent allows.
Sourcepub fn categories(
self,
categories: impl IntoIterator<Item = impl Into<String>>,
) -> Chart
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.
Sourcepub fn positions(self, positions: impl IntoIterator<Item = f64>) -> Chart
pub fn positions(self, positions: impl IntoIterator<Item = f64>) -> Chart
Where each point sits on the horizontal axis of a ChartKind::Scatter.
Sourcepub fn series(
self,
name: impl Into<String>,
values: impl IntoIterator<Item = f64>,
) -> Chart
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.
Sourcepub fn candles(self, candles: impl IntoIterator<Item = [f64; 4]>) -> Chart
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]]);Sourcepub fn series_color(
self,
name: impl Into<String>,
color: Color,
values: impl IntoIterator<Item = f64>,
) -> Chart
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.
Sourcepub fn hide_legend(self) -> Chart
pub fn hide_legend(self) -> Chart
Hides the legend, which otherwise appears when there is something to tell apart.
Sourcepub fn format(self, format: impl Fn(f64) -> String + 'static) -> Chart
pub fn format(self, format: impl Fn(f64) -> String + 'static) -> Chart
How numbers appear on the axis (at most two decimals by default).
Sourcepub fn size(self, width: f32, height: f32) -> Chart
pub fn size(self, width: f32, height: f32) -> Chart
Fixed size in logical pixels, for a sparkline in a row.
Sourcepub fn alt(self, text: impl Into<String>) -> Chart
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.
Sourcepub fn series_icon(self, name: &str, icon: IconName) -> Chart
pub fn series_icon(self, name: &str, icon: IconName) -> Chart
Gives the series called name an icon, for the legend and the tooltip.
Sourcepub fn curve(self, curve: Curve) -> Chart
pub fn curve(self, curve: Curve) -> Chart
How lines go from point to point (natural by default).
Sourcepub fn stack(self, stack: Stack) -> Chart
pub fn stack(self, stack: Stack) -> Chart
How series share a category: side by side by default, or stacked.
Sourcepub fn gradient(self) -> Chart
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.
Sourcepub fn fill_opacity(self, opacity: f32) -> Chart
pub fn fill_opacity(self, opacity: f32) -> Chart
How solid an area or a radar polygon is, from 0 to 1.
Sourcepub fn horizontal(self) -> Chart
pub fn horizontal(self) -> Chart
Bars lie down, with their categories on the left.
Sourcepub fn bars_from(self, from: ChartBarFrom) -> Chart
pub fn bars_from(self, from: ChartBarFrom) -> Chart
Where bars grow from: up from the bottom by default.
Sourcepub fn min_bar_length(self, length: f32) -> Chart
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.
Sourcepub fn labels_at_zero(self) -> Chart
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.
Sourcepub fn bar_radius(self, radius: f32) -> Chart
pub fn bar_radius(self, radius: f32) -> Chart
The corners of bars. In a stack, only its outer corners are round.
Sourcepub fn vary_colors(self) -> Chart
pub fn vary_colors(self) -> Chart
Gives each category its own color from the theme’s chart colors.
Sourcepub fn item_colors(self, colors: impl IntoIterator<Item = Semantic>) -> Chart
pub fn item_colors(self, colors: impl IntoIterator<Item = Semantic>) -> Chart
Gives the categories these colors, in order, over those of the series.
Sourcepub fn negative_color(self, color: Semantic) -> Chart
pub fn negative_color(self, color: Semantic) -> Chart
The color of bars below zero.
Sourcepub fn active(self, index: Option<usize>) -> Chart
pub fn active(self, index: Option<usize>) -> Chart
Makes one category stand out: a slice comes forward, a bar gets an outline.
Sourcepub fn dot_icon(self, icon: IconName) -> Chart
pub fn dot_icon(self, icon: IconName) -> Chart
Draws this icon on each point of a line, in place of a dot.
Sourcepub fn value_labels(self, at: LabelAt) -> Chart
pub fn value_labels(self, at: LabelAt) -> Chart
Writes each value beside the data.
Sourcepub fn category_labels(self, at: LabelAt) -> Chart
pub fn category_labels(self, at: LabelAt) -> Chart
Writes each category beside the data.
Sourcepub fn tick_format(self, format: impl Fn(&str) -> String + 'static) -> Chart
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.
Sourcepub fn grid_dashed(self) -> Chart
pub fn grid_dashed(self) -> Chart
Draws the gridlines in dashes.
Sourcepub fn grid_columns(self, columns: usize) -> Chart
pub fn grid_columns(self, columns: usize) -> Chart
Upright gridlines evenly spread into this many columns, instead of one at each category or number.
Sourcepub fn value_ticks(self, ticks: usize) -> Chart
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.
Sourcepub fn align_axis_ends(self) -> Chart
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.
Sourcepub fn value_domain(self, min: f64, max: f64) -> Chart
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.
Sourcepub fn reference_line(self, value: f64) -> Chart
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.
Sourcepub fn reference(self, reference: ChartReference) -> Chart
pub fn reference(self, reference: ChartReference) -> Chart
A dashed line across the data with its own text or color.
Sourcepub fn hide_category_axis(self) -> Chart
pub fn hide_category_axis(self) -> Chart
Leaves out the categories along the axis.
Sourcepub fn show_value_axis(self) -> Chart
pub fn show_value_axis(self) -> Chart
Writes numbers along the axis, which the tooltip otherwise makes unneeded.
Sourcepub fn tight_scale(self) -> Chart
pub fn tight_scale(self) -> Chart
The scale fits the values, instead of starting from zero. Not for bars.
Sourcepub fn no_separator(self) -> Chart
pub fn no_separator(self) -> Chart
Leaves out the gap between slices, through which what is behind the chart shows.
Sourcepub fn slice_radii(self, shares: impl IntoIterator<Item = f32>) -> Chart
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.
Sourcepub fn label_guides(self) -> Chart
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.
Sourcepub fn hole(self, share: f32) -> Chart
pub fn hole(self, share: f32) -> Chart
The hole of a doughnut or of rings, as a share of the radius.
Sourcepub fn concentric(self) -> Chart
pub fn concentric(self) -> Chart
One ring per series in a pie, instead of only the first series.
Sourcepub fn polar_grid(self, grid: PolarGrid) -> Chart
pub fn polar_grid(self, grid: PolarGrid) -> Chart
The shape of the grid of a radar or radial chart.
Sourcepub fn polar_fill(self) -> Chart
pub fn polar_fill(self) -> Chart
Fills the grid of a radar chart with the first color.
Sourcepub fn rings(self, rings: usize) -> Chart
pub fn rings(self, rings: usize) -> Chart
How many rings the grid of a radar chart has (5 by default).
Sourcepub fn lines_only(self) -> Chart
pub fn lines_only(self) -> Chart
Radar polygons with no fill.
Sourcepub fn radius_axis(self) -> Chart
pub fn radius_axis(self) -> Chart
Writes numbers along the radius of a radar chart.
Sourcepub fn angles(self, start: f32, sweep: f32) -> Chart
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.
Sourcepub fn center_text(
self,
value: impl Into<String>,
caption: impl Into<String>,
) -> Chart
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.
Sourcepub fn tooltip(self, tooltip: ChartTooltip) -> Chart
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.
Sourcepub fn hide_tooltip(self) -> Chart
pub fn hide_tooltip(self) -> Chart
Says nothing under the pointer and takes no keyboard focus.
Sourcepub fn no_hover_focus(self) -> Chart
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.
Sourcepub fn no_hover_motion(self) -> Chart
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.
Sourcepub fn no_appear(self) -> Chart
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.
Sourcepub fn animate_changes(self) -> Chart
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.
Sourcepub fn appear_key(self, key: impl Hash) -> Chart
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.
Sourcepub fn legend_at(self, at: ChartLegend) -> Chart
pub fn legend_at(self, at: ChartLegend) -> Chart
Where the legend goes (under the chart by default).
Trait Implementations§
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§
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
impl<T> AutoreleaseSafe for Twhere
T: ?Sized,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
impl<T, U> ToSample<U> for Twhere
U: FromSample<T>,
fn to_sample_(self) -> U
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.