Skip to main content

Chart

Struct Chart 

Source
pub struct Chart {
    pub style: Style,
    pub grid_color: Color,
    /* private fields */
}
Expand description

LVGL-parity chart widget.

Owns a list of named data series and draws them as ChartType::Line, ChartType::Bar, or ChartType::Scatter plots.

§Example

let mut chart = Chart::new(bounds);
let s = chart.add_series(Color(0, 120, 215, 255), ChartAxis::Primary);
chart.set_points(s, &[10, 40, 20, 80, 60]);

Fields§

§style: Style

Background and border style.

§grid_color: Color

Color used for the background grid div lines.

Implementations§

Source§

impl Chart

Source

pub fn new(bounds: Rect) -> Self

Create a chart with default settings: ChartType::Line, y range 0..=100, 10 points, 5×5 div lines.

Source

pub fn set_type(&mut self, t: ChartType)

Set the chart drawing type.

Source

pub fn chart_type(&self) -> ChartType

Return the current chart type.

Source

pub fn add_series(&mut self, color: Color, axis: ChartAxis) -> SeriesId

Append a new series drawn in color against axis.

The series starts with all points at 0. Returns the series id.

Source

pub fn set_point_count(&mut self, count: usize)

Resize all series to count points.

Existing values are preserved up to count; new slots are filled with 0.

Source

pub fn point_count(&self) -> usize

Return the current point count per series.

Source

pub fn set_point(&mut self, series: SeriesId, idx: usize, value: i32)

Set the value of one point in a series.

Out-of-range idx is silently ignored.

Source

pub fn get_point(&self, series: SeriesId, idx: usize) -> Option<i32>

Return the value of one point, or None if out of range.

Source

pub fn set_points(&mut self, series: SeriesId, values: &[i32])

Bulk-replace a series’ points from a slice (clamped to point_count).

Source

pub fn set_series_color(&mut self, series: SeriesId, color: Color)

Update the draw color for an existing series.

Source

pub fn set_axis_range(&mut self, _axis: ChartAxis, min: i32, max: i32)

Set the displayed value range for axis.

In v1, axis is ignored and all series share the same range.

Source

pub fn set_div_line_count(&mut self, h_div: u8, v_div: u8)

Set the number of horizontal and vertical background grid lines.

Source

pub fn h_div_line_count(&self) -> u8

Return horizontal div line count.

Source

pub fn v_div_line_count(&self) -> u8

Return vertical div line count.

Source

pub fn cursor_index(&self) -> Option<usize>

Return the current cursor index (0-based into the point axis), or None if no cursor is active.

Source

pub fn activate_cursor(&mut self)

Activate the cursor at the leftmost point.

Source

pub fn clear_cursor(&mut self)

Clear the cursor.

Source

pub fn navigate_cursor_left(&mut self)

Move the cursor one step to the left (wraps).

Wire this to ObjectEvent::Key(Key::ArrowLeft) in a node handler.

Source

pub fn navigate_cursor_right(&mut self)

Move the cursor one step to the right (wraps).

Wire this to ObjectEvent::Key(Key::ArrowRight) in a node handler.

Trait Implementations§

Source§

impl Widget for Chart

Source§

fn bounds(&self) -> Rect

Return the area this widget occupies relative to its parent.
Source§

fn set_bounds(&mut self, bounds: Rect)

Called by the LPAR-10 layout pass to notify this widget of its layout-computed bounds. Read more
Source§

fn draw(&self, renderer: &mut dyn Renderer)

Render the widget using the provided Renderer.
Source§

fn handle_event(&mut self, _event: &Event) -> bool

Handle an event and return true if it was consumed. Read more
Source§

fn clear_region(&mut self) -> Option<Rect>

Return a region (in draw/landscape coordinates) that should be restored from the pristine background copy, or None. Read more
Source§

fn widget_font_mut(&mut self) -> Option<&mut WidgetFont>

Expose this widget’s font slot for cascade-driven font resolution (FONT-05 §5.B). Read more

Auto Trait Implementations§

§

impl Freeze for Chart

§

impl RefUnwindSafe for Chart

§

impl Send for Chart

§

impl Sync for Chart

§

impl Unpin for Chart

§

impl UnsafeUnpin for Chart

§

impl UnwindSafe for Chart

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> 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<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, 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.