Skip to main content

basic_scatter/
basic_scatter.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//! Standalone scatter plot — no feature flags needed.
3
4use esoc_chart::v2::scatter;
5
6fn main() -> esoc_chart::error::Result<()> {
7    // Some synthetic data: y ≈ x² + noise
8    let x: Vec<f64> = (0..50).map(|i| f64::from(i) * 0.2).collect();
9    let y: Vec<f64> = x
10        .iter()
11        .map(|&xi| xi * xi + ((xi * 7.0).sin()) * 1.5)
12        .collect();
13
14    let svg = scatter(&x, &y)
15        .title("y = x² + noise")
16        .x_label("x")
17        .y_label("y")
18        .to_svg()?;
19
20    std::fs::write("basic_scatter.svg", &svg)?;
21    println!("Saved basic_scatter.svg ({} bytes)", svg.len());
22    Ok(())
23}