use embedded_charts::prelude::*;
#[path = "../common/mod.rs"]
mod common;
use common::{layout, window, WindowConfig};
#[cfg(feature = "std")]
fn main() -> ChartResult<()> {
let mut series = StaticDataSeries::<Point2D, 256>::new();
let data_points = [
(0.0, 20.0), (1.0, 22.0), (2.0, 25.0), (3.0, 28.0), (4.0, 30.0), (5.0, 27.0), (6.0, 24.0), (7.0, 21.0), ];
for (x, y) in data_points.iter() {
series
.push(Point2D::new(*x, *y))
.map_err(ChartError::from)?;
}
let chart = LineChart::builder()
.line_color(Rgb565::BLUE)
.line_width(2)
.with_title("Temperature Over Time")
.background_color(Rgb565::WHITE)
.build()?;
let legend = StandardLegendBuilder::new()
.position(LegendPos::Right)
.orientation(LegendOrientation::Vertical)
.add_line_entry("Temperature", Rgb565::BLUE)?
.professional_style()
.build()?;
let renderer = StandardLegendRenderer::new();
window::run(
WindowConfig::new("Line Chart Example")
.theme(common::WindowTheme::Default)
.background(Rgb565::WHITE),
move |display, viewport, _elapsed| {
layout::draw_chart_with_auto_legend(
|chart_area, display| chart.draw(&series, chart.config(), chart_area, display),
viewport,
display,
layout::ChartWithLegend::new(&legend, &renderer),
)
},
)
}
#[cfg(not(feature = "std"))]
fn main() {
println!("This example requires the 'std' feature to be enabled.");
println!("Run with: cargo run --example line_chart --features std");
}