Chart

Struct Chart 

Source
pub struct Chart<'a> { /* private fields */ }
Expand description

Chart for plotting data

Multiple Plots can be rendered in a single Chart, even with unrelated domains and axes.

Implementations§

Source§

impl<'a> Chart<'a>

Source

pub fn with_aspect_ratio(self, aspect: AspectRatio) -> Self

Adjust the aspect ratio

Source

pub fn with_title<T>(self, title: T) -> Self
where T: Into<Title>,

Add a chart title

Examples found in repository?
examples/area.rs (line 17)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Area::new("Series A", &domain, &data_a);
14    let plot_b = plot::Area::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Area Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
More examples
Hide additional examples
examples/scatter.rs (line 17)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Scatter::new("Series A", &domain, &data_a);
14    let plot_b = plot::Scatter::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Scatter Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
examples/line.rs (line 26)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b = vec![
11        (22.0, 50.0),
12        (105.0, 44.0),
13        (120.0, 67.0),
14        (180.0, 39.0),
15        (210.0, 43.0),
16    ];
17    let domain = {
18        let mut domain = BBox::new(data_a.iter().cloned());
19        domain.extend(data_b.iter().cloned());
20        domain
21    };
22    let plot_a = plot::Line::new("Series A", &domain, &data_a);
23    let plot_b = plot::Line::new("Series B", &domain, &data_b);
24    let page = Page::default().with_chart(
25        Chart::default()
26            .with_title("Line Plot")
27            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
28            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
29            .with_axis(Vertical::new(domain).on_right())
30            .with_plot(&plot_a)
31            .with_plot(&plot_b),
32    );
33    print!("{}", page);
34}
Source

pub fn with_axis<A: Axis + 'a>(self, axis: A) -> Self

Add an Axis

Examples found in repository?
examples/area.rs (line 18)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Area::new("Series A", &domain, &data_a);
14    let plot_b = plot::Area::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Area Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
More examples
Hide additional examples
examples/scatter.rs (line 18)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Scatter::new("Series A", &domain, &data_a);
14    let plot_b = plot::Scatter::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Scatter Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
examples/line.rs (line 27)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b = vec![
11        (22.0, 50.0),
12        (105.0, 44.0),
13        (120.0, 67.0),
14        (180.0, 39.0),
15        (210.0, 43.0),
16    ];
17    let domain = {
18        let mut domain = BBox::new(data_a.iter().cloned());
19        domain.extend(data_b.iter().cloned());
20        domain
21    };
22    let plot_a = plot::Line::new("Series A", &domain, &data_a);
23    let plot_b = plot::Line::new("Series B", &domain, &data_b);
24    let page = Page::default().with_chart(
25        Chart::default()
26            .with_title("Line Plot")
27            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
28            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
29            .with_axis(Vertical::new(domain).on_right())
30            .with_plot(&plot_a)
31            .with_plot(&plot_b),
32    );
33    print!("{}", page);
34}
Source

pub fn with_plot(self, plot: &'a dyn Plot) -> Self

Add a Plot

Examples found in repository?
examples/area.rs (line 21)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Area::new("Series A", &domain, &data_a);
14    let plot_b = plot::Area::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Area Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
More examples
Hide additional examples
examples/scatter.rs (line 21)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b =
11        vec![(22.0, 50.0), (105.0, 44.0), (120.0, 67.0), (180.0, 39.0)];
12    let domain = BBox::new(data_a.iter().cloned());
13    let plot_a = plot::Scatter::new("Series A", &domain, &data_a);
14    let plot_b = plot::Scatter::new("Series B", &domain, &data_b);
15    let page = Page::default().with_chart(
16        Chart::default()
17            .with_title("Scatter Plot")
18            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
19            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
20            .with_axis(Vertical::new(domain).on_right())
21            .with_plot(&plot_a)
22            .with_plot(&plot_b),
23    );
24    print!("{}", page);
25}
examples/line.rs (line 30)
7fn main() {
8    let data_a =
9        vec![(13.0, 74.0), (111.0, 37.0), (125.0, 52.0), (190.0, 66.0)];
10    let data_b = vec![
11        (22.0, 50.0),
12        (105.0, 44.0),
13        (120.0, 67.0),
14        (180.0, 39.0),
15        (210.0, 43.0),
16    ];
17    let domain = {
18        let mut domain = BBox::new(data_a.iter().cloned());
19        domain.extend(data_b.iter().cloned());
20        domain
21    };
22    let plot_a = plot::Line::new("Series A", &domain, &data_a);
23    let plot_b = plot::Line::new("Series B", &domain, &data_b);
24    let page = Page::default().with_chart(
25        Chart::default()
26            .with_title("Line Plot")
27            .with_axis(Horizontal::new(domain).with_name("X Axis Name"))
28            .with_axis(Vertical::new(domain).with_name("Y Axis Name"))
29            .with_axis(Vertical::new(domain).on_right())
30            .with_plot(&plot_a)
31            .with_plot(&plot_b),
32    );
33    print!("{}", page);
34}

Trait Implementations§

Source§

impl<'a> Default for Chart<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> Display for Chart<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Chart<'a>

§

impl<'a> !RefUnwindSafe for Chart<'a>

§

impl<'a> !Send for Chart<'a>

§

impl<'a> !Sync for Chart<'a>

§

impl<'a> Unpin for Chart<'a>

§

impl<'a> !UnwindSafe for Chart<'a>

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> 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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.