pub struct Dataset<'a> { /* private fields */ }Expand description
A group of data points
This is the main element composing a Chart.
A dataset can be named. Only named datasets will be rendered in the legend.
After that, you can pass it data with Dataset::data. Data is an array of f64 tuples
((f64, f64)), the first element being X and the second Y. It’s also worth noting that, unlike
the Rect, here the Y axis is bottom to top, as in math.
You can also customize the rendering by using Dataset::marker and Dataset::graph_type.
§Example
This example draws a red line between two points.
use ratatui::{
style::Stylize,
symbols::Marker,
widgets::{Dataset, GraphType},
};
let dataset = Dataset::default()
.name("dataset 1")
.data(&[(1., 1.), (5., 5.)])
.marker(Marker::Braille)
.graph_type(GraphType::Line)
.red();Implementations§
Source§impl<'a> Dataset<'a>
impl<'a> Dataset<'a>
Sourcepub fn name<S>(self, name: S) -> Self
pub fn name<S>(self, name: S) -> Self
Sets the name of the dataset
The dataset’s name is used when displaying the chart legend. Datasets don’t require a name and can be created without specifying one. Once assigned, a name can’t be removed, only changed
The name can be styled (see Line for that), but the dataset’s style will always have
precedence.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn data(self, data: &'a [(f64, f64)]) -> Self
pub const fn data(self, data: &'a [(f64, f64)]) -> Self
Sets the data points of this dataset
Points will then either be rendered as scattered points or with lines between them
depending on Dataset::graph_type.
Data consist in an array of f64 tuples ((f64, f64)), the first element being X and the
second Y. It’s also worth noting that, unlike the Rect, here the Y axis is bottom to
top, as in math.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn marker(self, marker: Marker) -> Self
pub const fn marker(self, marker: Marker) -> Self
Sets the kind of character to use to display this dataset
You can use dots (•), blocks (█), bars (▄), braille (⠓, ⣇, ⣿) or half-blocks
(█, ▄, and ▀). See symbols::Marker for more details.
Note Marker::Braille requires a font that supports Unicode
Braille Patterns.
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub const fn graph_type(self, graph_type: GraphType) -> Self
pub const fn graph_type(self, graph_type: GraphType) -> Self
Sets how the dataset should be drawn
Chart can draw scatter, line or
bar charts. A scatter chart draws only the points in the dataset, a line
char draws a line between each point, and a bar chart draws a line from the x axis to the
point. See GraphType for more details
This is a fluent setter method which must be chained or used as it consumes self
Sourcepub fn style<S: Into<Style>>(self, style: S) -> Self
pub fn style<S: Into<Style>>(self, style: S) -> Self
Sets the style of this dataset
The given style will be used to draw the legend and the data points. Currently the legend will use the entire style whereas the data points will only use the foreground.
style accepts any type that is convertible to Style (e.g. Style, Color, or
your own type that implements Into<Style>).
This is a fluent setter method which must be chained or used as it consumes self
§Example
Dataset also implements Stylize which mean you can style it
like so
use ratatui::{style::Stylize, widgets::Dataset};
let dataset = Dataset::default().red();Trait Implementations§
impl<'a> StructuralPartialEq for Dataset<'a>
Auto Trait Implementations§
impl<'a> Freeze for Dataset<'a>
impl<'a> RefUnwindSafe for Dataset<'a>
impl<'a> Send for Dataset<'a>
impl<'a> Sync for Dataset<'a>
impl<'a> Unpin for Dataset<'a>
impl<'a> UnwindSafe for Dataset<'a>
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,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
impl<'a, T, U> Stylize<'a, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
ITALIC modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
UNDERLINED modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
UNDERLINED modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
SLOW_BLINK modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
RAPID_BLINK modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
REVERSED modifier.HIDDEN modifier.HIDDEN modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
CROSSED_OUT modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
CROSSED_OUT modifier.