Struct piechart::Chart[][src]

pub struct Chart { /* fields omitted */ }

The Chart struct contains the configuration for displaying some data.

By default, a chart has a radius of 9, an aspect ratio of 2 and doesn’t show its legend.

Example usage:

use piechart::{Chart, Color, Data};

let data = vec![
    Data { label: "Chocolate".into(), value: 4.0, color: Some(Color::Blue.into()), fill: '•' },
    Data { label: "Strawberry".into(), value: 2.0, color: Some(Color::Red.into()), fill: '▪' },
    Data { label: "Vanilla".into(), value: 2.6, color: Some(Color::Yellow.into()), fill: '▴' },
];

Chart::new()
    .radius(9)
    .aspect_ratio(3)
    .legend(true)
    .draw(&data);

will result in

example image

Implementations

impl Chart[src]

pub fn new() -> Self[src]

Contructs a new chart initialized with its default values

pub fn radius(&mut self, radius: u16) -> &mut Self[src]

Sets the radius of the pie chart. To choose which size fits the best, you can run a code snippet like this:

let mut chart = Chart::new();
for radius in 0..=12 {
    chart.radius(radius);
    chart.draw(&data);
}

pub fn aspect_ratio(&mut self, aspect_ratio: u16) -> &mut Self[src]

The aspect ratio controls how stretched or squished the circle is. Since terminal columns are more tall than wide a ration of 2 or 3 is the best in most cases.

pub fn legend(&mut self, legend: bool) -> &mut Self[src]

Specifies whether the chart should render a legend with the labels and their percentages.

impl Chart[src]

pub fn draw(&self, data: &[Data])[src]

Renders the chart and outputs it onto stdout. The method panics in case of an error. If you want more fine-grained control about error recovery and how the buffer the chart is rendered into the buffer, use Chart::draw_into.

pub fn draw_into(&self, f: impl Write, data: &[Data]) -> Result<()>[src]

Same as Chart::draw, but you can supply your own impl Write and you can handle errors gracefully.

Trait Implementations

impl Debug for Chart[src]

impl Default for Chart[src]

Auto Trait Implementations

impl RefUnwindSafe for Chart

impl Send for Chart

impl Sync for Chart

impl Unpin for Chart

impl UnwindSafe for Chart

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.