pub struct LineChart<C: PixelColor> { /* private fields */ }Expand description
Line chart implementation for displaying continuous data series.
A line chart connects data points with straight lines (or smooth curves when enabled), making it ideal for showing trends over time or continuous relationships between variables. This implementation is optimized for embedded systems with static memory allocation and efficient rendering.
§Features
- Configurable line styling (color, width, smoothing)
- Optional markers at data points with various shapes
- Area filling under the line
- Integration with grid systems and axes
- Support for animations and real-time data streaming
§Memory Usage
The line chart uses static allocation with a maximum of 256 data points per series. Additional memory is used for:
- Screen coordinate transformation (256 points)
- Area fill polygon vertices (258 points maximum)
- Grid and axis rendering buffers
§Examples
Basic line chart:
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let chart: LineChart<Rgb565> = LineChart::new();
let mut data: StaticDataSeries<Point2D, 256> = StaticDataSeries::new();
data.push(Point2D::new(0.0, 10.0))?;
data.push(Point2D::new(1.0, 20.0))?;Styled line chart with markers:
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let chart = LineChart::builder()
.line_color(Rgb565::BLUE)
.line_width(2)
.with_markers(MarkerStyle {
shape: MarkerShape::Circle,
size: 6,
color: Rgb565::RED,
visible: true,
})
.build()?;Implementations§
Source§impl<C> LineChart<C>
impl<C> LineChart<C>
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new line chart with default styling.
This creates a line chart with:
- Blue line color
- 1-pixel line width
- No area fill
- No markers
- No smoothing
- Default margins (10 pixels on all sides)
§Examples
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let chart: LineChart<Rgb565> = LineChart::new();Sourcepub fn builder() -> LineChartBuilder<C>
pub fn builder() -> LineChartBuilder<C>
Create a builder for configuring the line chart.
The builder pattern provides a fluent interface for configuring all aspects of the line chart before creation.
§Examples
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let chart = LineChart::builder()
.line_color(Rgb565::BLUE)
.line_width(2)
.with_markers(MarkerStyle::default())
.build()?;Sourcepub fn set_style(&mut self, style: LineChartStyle<C>)
pub fn set_style(&mut self, style: LineChartStyle<C>)
Set the line style configuration.
This replaces the entire style configuration with the provided one. Use the builder pattern for more granular control.
§Arguments
style- The new line chart style configuration
§Examples
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let mut chart = LineChart::new();
let style = LineChartStyle {
line_color: Rgb565::RED,
line_width: 3,
fill_area: true,
fill_color: Some(Rgb565::CSS_LIGHT_CORAL),
markers: None,
smooth: false,
smooth_subdivisions: 8,
};
chart.set_style(style);Sourcepub fn style(&self) -> &LineChartStyle<C>
pub fn style(&self) -> &LineChartStyle<C>
Get the current line style configuration.
Returns a reference to the current style configuration, allowing inspection of current settings.
§Returns
A reference to the current LineChartStyle
Sourcepub fn set_config(&mut self, config: ChartConfig<C>)
pub fn set_config(&mut self, config: ChartConfig<C>)
Set the chart configuration.
This includes general chart settings like title, background color, margins, and grid visibility.
§Arguments
config- The new chart configuration
Sourcepub fn config(&self) -> &ChartConfig<C>
pub fn config(&self) -> &ChartConfig<C>
Sourcepub fn set_grid(&mut self, grid: Option<GridSystem<C>>)
pub fn set_grid(&mut self, grid: Option<GridSystem<C>>)
Set the grid system for the chart.
The grid system draws background grid lines to help with data reading.
Pass None to disable the grid.
§Arguments
grid- Optional grid system configuration
§Examples
use embedded_charts::prelude::*;
use embedded_graphics::pixelcolor::Rgb565;
let mut chart: LineChart<Rgb565> = LineChart::new();
// Grid configuration is simplified in this example
let grid: LinearGrid<Rgb565> = LinearGrid::new(GridOrientation::Horizontal, GridSpacing::DataUnits(10.0));
// chart.set_grid(Some(grid)); // Grid system API still evolvingSourcepub fn grid(&self) -> Option<&GridSystem<C>>
pub fn grid(&self) -> Option<&GridSystem<C>>
Get the current grid system configuration.
§Returns
An optional reference to the current grid system