Chart

Struct Chart 

Source
pub struct Chart<'a, P>
where P: IntoPoint,
{ /* private fields */ }
Expand description

Chart for plotting data to SVG

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

Implementations§

Source§

impl<'a, P> Chart<'a, P>
where P: IntoPoint,

Source

pub fn new() -> Self

Create a new chart

Examples found in repository?
examples/line.rs (line 5)
3fn main() {
4    let data = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let chart = Chart::new()
6        .title("Line Plot")
7        .domain(Domain::from(&data[..]).set_x(&[0.0, 200.0]))
8        .axis("X Axis", Edge::Bottom)
9        .axis("Y Axis", Edge::Left)
10        .plot(Plot::line("Series", &data));
11    print!("{chart}");
12}
More examples
Hide additional examples
examples/area.rs (line 7)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Area Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::area("Series A", &data_a))
14            .plot(Plot::area("Series B", &data_b)),
15    );
16    print!("{page}");
17}
examples/scatter.rs (line 7)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Scatter Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::scatter("Series A", &data_a).label())
14            .plot(Plot::scatter("Series B", &data_b)),
15    );
16    print!("{page}");
17}
Source

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

Adjust the aspect ratio

Source

pub fn domain<D>(self, domain: D) -> Self
where D: Into<Domain>,

Set the domain

Panics if called after axis or plot.

Examples found in repository?
examples/line.rs (line 7)
3fn main() {
4    let data = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let chart = Chart::new()
6        .title("Line Plot")
7        .domain(Domain::from(&data[..]).set_x(&[0.0, 200.0]))
8        .axis("X Axis", Edge::Bottom)
9        .axis("Y Axis", Edge::Left)
10        .plot(Plot::line("Series", &data));
11    print!("{chart}");
12}
More examples
Hide additional examples
examples/area.rs (line 9)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Area Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::area("Series A", &data_a))
14            .plot(Plot::area("Series B", &data_b)),
15    );
16    print!("{page}");
17}
examples/scatter.rs (line 9)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Scatter Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::scatter("Series A", &data_a).label())
14            .plot(Plot::scatter("Series B", &data_b)),
15    );
16    print!("{page}");
17}
Source

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

Add a chart title

Panics if called after axis or plot.

Examples found in repository?
examples/line.rs (line 6)
3fn main() {
4    let data = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let chart = Chart::new()
6        .title("Line Plot")
7        .domain(Domain::from(&data[..]).set_x(&[0.0, 200.0]))
8        .axis("X Axis", Edge::Bottom)
9        .axis("Y Axis", Edge::Left)
10        .plot(Plot::line("Series", &data));
11    print!("{chart}");
12}
More examples
Hide additional examples
examples/area.rs (line 8)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Area Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::area("Series A", &data_a))
14            .plot(Plot::area("Series B", &data_b)),
15    );
16    print!("{page}");
17}
examples/scatter.rs (line 8)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Scatter Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::scatter("Series A", &data_a).label())
14            .plot(Plot::scatter("Series B", &data_b)),
15    );
16    print!("{page}");
17}
Source

pub fn axis(self, name: &'a str, edge: Edge) -> Self

Add an Axis

Panics if called after plot.

Examples found in repository?
examples/line.rs (line 8)
3fn main() {
4    let data = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let chart = Chart::new()
6        .title("Line Plot")
7        .domain(Domain::from(&data[..]).set_x(&[0.0, 200.0]))
8        .axis("X Axis", Edge::Bottom)
9        .axis("Y Axis", Edge::Left)
10        .plot(Plot::line("Series", &data));
11    print!("{chart}");
12}
More examples
Hide additional examples
examples/area.rs (line 10)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Area Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::area("Series A", &data_a))
14            .plot(Plot::area("Series B", &data_b)),
15    );
16    print!("{page}");
17}
examples/scatter.rs (line 10)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Scatter Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::scatter("Series A", &data_a).label())
14            .plot(Plot::scatter("Series B", &data_b)),
15    );
16    print!("{page}");
17}
Source

pub fn plot(self, plot: Plot<'a, P>) -> Self

Add a Plot

Examples found in repository?
examples/line.rs (line 10)
3fn main() {
4    let data = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let chart = Chart::new()
6        .title("Line Plot")
7        .domain(Domain::from(&data[..]).set_x(&[0.0, 200.0]))
8        .axis("X Axis", Edge::Bottom)
9        .axis("Y Axis", Edge::Left)
10        .plot(Plot::line("Series", &data));
11    print!("{chart}");
12}
More examples
Hide additional examples
examples/area.rs (line 13)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Area Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::area("Series A", &data_a))
14            .plot(Plot::area("Series B", &data_b)),
15    );
16    print!("{page}");
17}
examples/scatter.rs (line 13)
3fn main() {
4    let data_a = vec![(13, 74), (111, 37), (125, 52), (190, 66)];
5    let data_b = vec![(22, 50), (105, 44), (120, 67), (180, 39)];
6    let page = Page::new().chart(
7        Chart::new()
8            .title("Scatter Plot")
9            .domain(&data_a[..])
10            .axis("X Axis", Edge::Bottom)
11            .axis("Y Axis", Edge::Left)
12            .axis("", Edge::Right)
13            .plot(Plot::scatter("Series A", &data_a).label())
14            .plot(Plot::scatter("Series B", &data_b)),
15    );
16    print!("{page}");
17}
Source

pub fn display(&self, html: &mut Html)

Display char as HTML

Source

pub fn legend(&self, html: &mut Html)

Display legend as HTML <div>

Trait Implementations§

Source§

impl<P> Default for Chart<'_, P>
where P: IntoPoint,

Source§

fn default() -> Self

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

impl<P> Display for Chart<'_, P>
where P: IntoPoint,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a, P> RefUnwindSafe for Chart<'a, P>
where P: RefUnwindSafe,

§

impl<'a, P> Send for Chart<'a, P>
where P: Sync,

§

impl<'a, P> Sync for Chart<'a, P>
where P: Sync,

§

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

§

impl<'a, P> UnwindSafe for Chart<'a, P>
where P: RefUnwindSafe,

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.