LineChart

Struct LineChart 

Source
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>
where C: From<Rgb565> + PixelColor,

Source

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();
Source

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()?;
Source

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);
Source

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

Source

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
Source

pub fn config(&self) -> &ChartConfig<C>

Get the current chart configuration.

§Returns

A reference to the current ChartConfig

Source

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 evolving
Source

pub fn grid(&self) -> Option<&GridSystem<C>>

Get the current grid system configuration.

§Returns

An optional reference to the current grid system

Trait Implementations§

Source§

impl<C> AxisChart<C> for LineChart<C>
where C: From<Rgb565> + PixelColor + 'static,

Source§

type XAxis = LinearAxis<f32, C>

X-axis type
Source§

type YAxis = LinearAxis<f32, C>

Y-axis type
Source§

fn set_x_axis(&mut self, axis: LinearAxis<f32, C>)

Set the X-axis configuration Read more
Source§

fn set_y_axis(&mut self, axis: LinearAxis<f32, C>)

Set the Y-axis configuration Read more
Source§

fn x_axis(&self) -> ChartResult<&LinearAxis<f32, C>>

Get the X-axis configuration
Source§

fn y_axis(&self) -> ChartResult<&LinearAxis<f32, C>>

Get the Y-axis configuration
Source§

impl<C> Chart<C> for LineChart<C>
where C: From<Rgb565> + PixelColor + 'static,

Source§

type Data = StaticDataSeries<Point2D, 256>

The type of data this chart can render
Source§

type Config = ChartConfig<C>

Configuration type for this chart
Source§

fn draw<D>( &self, data: &Self::Data, config: &Self::Config, viewport: Rectangle, target: &mut D, ) -> ChartResult<()>
where D: DrawTarget<Color = C>, Self::Data: DataSeries, <Self::Data as DataSeries>::Item: DataPoint, <<Self::Data as DataSeries>::Item as DataPoint>::X: Into<f32> + Copy + PartialOrd, <<Self::Data as DataSeries>::Item as DataPoint>::Y: Into<f32> + Copy + PartialOrd,

Draw the chart to the target display Read more
Source§

fn data_bounds(&self, _data: &Self::Data) -> ChartResult<()>

Get the data bounds for this chart
Source§

impl<C: Debug + PixelColor> Debug for LineChart<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C> Default for LineChart<C>
where C: From<Rgb565> + PixelColor,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for LineChart<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for LineChart<C>
where C: RefUnwindSafe,

§

impl<C> Send for LineChart<C>
where C: Send,

§

impl<C> Sync for LineChart<C>
where C: Sync,

§

impl<C> Unpin for LineChart<C>
where C: Unpin,

§

impl<C> UnwindSafe for LineChart<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.