use embedded_charts::prelude::*;
#[path = "../common/mod.rs"]
mod common;
use common::{configs, layout, window, WindowConfig};
#[cfg(feature = "std")]
fn main() -> ChartResult<()> {
let mut series = StaticDataSeries::<Point2D, 256>::new();
let data_points = [
(1.0, 35.0), (2.0, 25.0), (3.0, 20.0), (4.0, 15.0), (5.0, 5.0), ];
for (x, y) in data_points.iter() {
series
.push(Point2D::new(*x, *y))
.map_err(ChartError::from)?;
}
let colors = configs::standard_colors();
println!("=== PIE CHART COLOR DEBUG ===");
println!("Standard colors from configs:");
for (i, color) in colors[0..5].iter().enumerate() {
println!(
" [{}]: RGB({}, {}, {})",
i,
color.r(),
color.g(),
color.b()
);
}
let chart = PieChart::builder()
.radius(100) .colors(&colors[0..5])
.with_title("Market Share")
.build()?;
println!("Chart colors after building:");
for (i, color) in chart.style().colors.iter().enumerate() {
println!(
" [{}]: RGB({}, {}, {})",
i,
color.r(),
color.g(),
color.b()
);
}
let legend = StandardLegendBuilder::new()
.position(LegendPos::Right)
.orientation(LegendOrientation::Vertical)
.add_pie_entry("Company A", colors[0])?
.add_pie_entry("Company B", colors[1])?
.add_pie_entry("Company C", colors[2])?
.add_pie_entry("Company D", colors[3])?
.add_pie_entry("Others", colors[4])?
.professional_style()
.build()?;
let renderer = StandardLegendRenderer::new();
window::run_static(
WindowConfig::new("Pie Chart Example")
.theme(common::WindowTheme::Default)
.background(Rgb565::WHITE),
move |display, viewport| {
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() {
utils::print_feature_requirement("std", "visual");
}