Skip to content

How do you use chart.draw_series() inside a function with iterable as parameter to draw_series? #351

Discussion options

You must be logged in to vote

I'm not sure how I'd have solved it without compiler hints suggesting
for<'b> &'b plotters::element::DynElement<'static, plotters::prelude::SVGBackend<'a>, Coord>: plotters::element::PointCollection<'b, (f32, f32)>
Solution:

use plotters::prelude::*;
use std::{env, error::Error};

fn main() -> Result<(), Box<dyn std::error::Error>> {

    draw_fn((-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x /(x*15.*x))))?;

    Ok(())
}

fn draw_fn <'a,Coord, I>(iter: I) -> Result<(), Box<dyn Error>> 
    where 
    I: Iterator<Item = Coord>, 
    for<'b> &'b plotters::element::DynElement<'static, plotters::prelude::SVGBackend<'a>, Coord>: plotters::element::PointCollection<'b, (f32, f32)>, 
    Coor…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by codecnotsupported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant