plotters-rs / plotters

A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀
https://plotters-rs.github.io/home/
MIT License
3.81k stars 276 forks source link

Can I add text in the graph? #476

Open baiguoname opened 1 year ago

baiguoname commented 1 year ago

I tried add a multi lines text in the graph, but the text can only shown in one line, like this: pub fn plot_test() -> evcxr::SVGWrapper { evcxr_figure((500, 500), |root| { root.fill(&WHITE)?; let te = Text::new(format!("a \n b"), (40, 20), ("sans-serif", 15.0).into_font()); root.draw(&te)?; Ok(()) }) }

图片 As can be seen in the above figure, the "\n" between a and b does not work.

matteopolak commented 1 year ago

If you know exactly where you want to put the text, you could draw the chart to a buffer, drop the chart, then pass the buffer directly into skia_safe and draw the text from there

AliMMehr commented 10 months ago

There is a MultiLineText, which can show a multiline string. I mean you need to call MultiLineText::push_line() multiple times to push your lines into it one by one.