summaryrefslogtreecommitdiffstats
path: root/vendor/plotters/examples/pie.rs
blob: a950c021820178c74234bdb299f49e918203ba3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use plotters::{prelude::*, style::full_palette::ORANGE};

const OUT_FILE_NAME: &'static str = "plotters-doc-data/pie-chart.png";
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let root_area = BitMapBackend::new(&OUT_FILE_NAME, (950, 700)).into_drawing_area();
    root_area.fill(&WHITE).unwrap();
    let title_style = TextStyle::from(("sans-serif", 30).into_font()).color(&(BLACK));
    root_area.titled("BEST CIRCLES", title_style).unwrap();

    let dims = root_area.dim_in_pixel();
    let center = (dims.0 as i32 / 2, dims.1 as i32 / 2);
    let radius = 300.0;
    let sizes = vec![66.0, 33.0];
    let _rgba = RGBAColor(0, 50, 255, 1.0);
    let colors = vec![RGBColor(0, 50, 255), CYAN];
    let labels = vec!["Pizza", "Pacman"];

    let mut pie = Pie::new(&center, &radius, &sizes, &colors, &labels);
    pie.start_angle(66.0);
    pie.label_style((("sans-serif", 50).into_font()).color(&(ORANGE)));
    pie.percentages((("sans-serif", radius * 0.08).into_font()).color(&BLACK));
    root_area.draw(&pie)?;

    Ok(())
}