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: StyleBackground and border style.
grid_color: ColorColor used for the background grid div lines.
Implementations§
Source§impl Chart
impl Chart
Sourcepub fn new(bounds: Rect) -> Self
pub fn new(bounds: Rect) -> Self
Create a chart with default settings:
ChartType::Line, y range 0..=100, 10 points, 5×5 div lines.
Sourcepub fn chart_type(&self) -> ChartType
pub fn chart_type(&self) -> ChartType
Return the current chart type.
Sourcepub fn add_series(&mut self, color: Color, axis: ChartAxis) -> SeriesId
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.
Sourcepub fn set_point_count(&mut self, count: usize)
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.
Sourcepub fn point_count(&self) -> usize
pub fn point_count(&self) -> usize
Return the current point count per series.
Sourcepub fn set_point(&mut self, series: SeriesId, idx: usize, value: i32)
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.
Sourcepub fn get_point(&self, series: SeriesId, idx: usize) -> Option<i32>
pub fn get_point(&self, series: SeriesId, idx: usize) -> Option<i32>
Return the value of one point, or None if out of range.
Sourcepub fn set_points(&mut self, series: SeriesId, values: &[i32])
pub fn set_points(&mut self, series: SeriesId, values: &[i32])
Bulk-replace a series’ points from a slice (clamped to point_count).
Sourcepub fn set_series_color(&mut self, series: SeriesId, color: Color)
pub fn set_series_color(&mut self, series: SeriesId, color: Color)
Update the draw color for an existing series.
Sourcepub fn set_axis_range(&mut self, _axis: ChartAxis, min: i32, max: i32)
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.
Sourcepub fn set_div_line_count(&mut self, h_div: u8, v_div: u8)
pub fn set_div_line_count(&mut self, h_div: u8, v_div: u8)
Set the number of horizontal and vertical background grid lines.
Sourcepub fn h_div_line_count(&self) -> u8
pub fn h_div_line_count(&self) -> u8
Return horizontal div line count.
Sourcepub fn v_div_line_count(&self) -> u8
pub fn v_div_line_count(&self) -> u8
Return vertical div line count.
Sourcepub fn cursor_index(&self) -> Option<usize>
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.
Sourcepub fn activate_cursor(&mut self)
pub fn activate_cursor(&mut self)
Activate the cursor at the leftmost point.
Sourcepub fn clear_cursor(&mut self)
pub fn clear_cursor(&mut self)
Clear the cursor.
Move the cursor one step to the left (wraps).
Wire this to ObjectEvent::Key(Key::ArrowLeft) in a node handler.
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
impl Widget for Chart
Source§fn set_bounds(&mut self, bounds: Rect)
fn set_bounds(&mut self, bounds: Rect)
Source§fn handle_event(&mut self, _event: &Event) -> bool
fn handle_event(&mut self, _event: &Event) -> bool
true if it was consumed. Read moreSource§fn clear_region(&mut self) -> Option<Rect>
fn clear_region(&mut self) -> Option<Rect>
None. Read more