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