Skip to main content

Chart

Struct Chart 

Source
pub struct Chart { /* private fields */ }
Expand description

A chart, bound to one canvas element.

The chart owns its option, its layout, and its display list. Setting an option invalidates the layout; rendering rebuilds both and hands the resulting display list to the backend.

The backend is chosen when the chart is created: WebGPU if the host has it, WebGL2 if it does not, Canvas2D otherwise. From the outside the three behave identically — the same option produces the same picture, and the same API draws it.

Implementations§

Source§

impl Chart

Inherent implementation of Chart.

Source

pub async fn create(canvas: HtmlCanvasElement) -> Option<Self>

Creates a chart on the given canvas.

The backend is chosen automatically: WebGPU when the host has it, WebGL2 when it does not, and Canvas2D everywhere else. The chart looks the same whichever one it gets.

Returns None when the host has no DOM, or when the canvas cannot give out a rendering context at all.

§Arguments
  • HtmlCanvasElement - The HtmlCanvasElement value.
§Returns
  • Option<Self> - The Option<Self> value.
Source

pub async fn create_with_backend( canvas: HtmlCanvasElement, preferred: BackendKind, ) -> Option<Self>

Creates a chart on the given canvas, preferring a particular backend.

The preference is honoured when the host can provide it; the factory falls back to the next backend down when it cannot.

§Arguments
  • HtmlCanvasElement - The HtmlCanvasElement value.
  • BackendKind - The BackendKind value.
§Returns
  • Option<Self> - The Option<Self> value.
Source

pub fn set_option(&mut self, option: ChartOption) -> &mut Self

Sets the configuration of the chart.

The chart is re-laid out and re-rendered. When the chart animates, the new configuration is the target of the animation and the chart moves towards it; call Chart::advance to move it along.

§Arguments
  • ChartOption - A ChartOption parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn advance(&mut self, delta: f64) -> bool

Advances the animation by the given number of milliseconds.

Returns true when the animation is still running. The call re-renders the chart, so an animation loop is a call to advance once per frame.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • bool - A boolean.
Source

pub fn animator(&mut self) -> &mut Animator

Returns the animator of the chart.

§Returns
  • &mut Animator - A mut Animator value.
Source

pub fn option(&self) -> &ChartOption

Returns the configuration of the chart.

§Returns
  • &ChartOption - A ChartOption value.
Source

pub fn option_mut(&mut self) -> &mut ChartOption

Returns the configuration of the chart, mutably.

Changing the configuration marks the chart as needing a new layout; call Chart::render to apply the change.

§Returns
  • &mut ChartOption - A mut ChartOption value.
Source

pub fn render(&mut self) -> &mut Self

Lays the chart out and draws it.

The call is cheap when nothing changed: the layout and the display list are only rebuilt when the option or the size changed.

§Returns
  • &mut Self - A mut Self value.
Source

pub fn handle(&self) -> ChartHandle

Returns a handle to the chart.

The handle is how an application that does not hold the chart talks to it: the commands it sends travel through a signal, and the chart performs them on its next frame.

§Returns
  • ChartHandle - A ChartHandle value.
Source

pub fn resize(&mut self, width: f64, height: f64) -> &mut Self

Resizes the chart.

The size is in CSS pixels; the chart multiplies it by the device pixel ratio to get the size of the drawing buffer.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • &mut Self - A mut Self value.
Source

pub fn backend_kind(&self) -> BackendKind

Returns the kind of the backend the chart runs on.

§Returns
  • BackendKind - A BackendKind value.
Source

pub fn layout(&self) -> &ChartLayout

Returns the layout of the chart.

§Returns
  • &ChartLayout - A ChartLayout value.
Source

pub fn display_list(&self) -> &DisplayList

Returns the display list the chart draws.

§Returns
  • &DisplayList - A DisplayList value.
Source

pub fn canvas(&self) -> &HtmlCanvasElement

Returns the canvas the chart draws into.

§Returns
  • &HtmlCanvasElement - A HtmlCanvasElement value.
Source

pub fn on( &mut self, event_type: ChartEventType, handler: EventHandler, ) -> &mut Self

Registers a handler for a kind of event.

§Arguments
  • ChartEventType - A ChartEventType parameter.
  • EventHandler - A EventHandler parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn off(&mut self, event_type: ChartEventType) -> &mut Self

Removes every handler registered for a kind of event.

§Arguments
  • ChartEventType - A ChartEventType parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn emit(&mut self, event: ChartEvent) -> &mut Self

Dispatches an event to the registered handlers.

§Arguments
  • ChartEvent - A ChartEvent parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn dispatch_action(&mut self, action: ChartAction) -> &mut Self

Performs an action.

Actions are how an application drives a chart: the same mechanism ECharts calls dispatchAction, but expressed as a method on the chart rather than a free function.

§Arguments
  • ChartAction - A ChartAction parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn show_tip( &mut self, series_index: usize, data_index: usize, x: f64, y: f64, ) -> &mut Self

Shows the tooltip over a data point.

§Arguments
  • usize - A non-negative integer (usize).
  • f64 - A 64-bit float (f64).
§Returns
  • &mut Self - A mut Self value.
Source

pub fn hide_tip(&mut self) -> &mut Self

Hides the tooltip.

§Returns
  • &mut Self - A mut Self value.
Source

pub fn tooltip(&self) -> Option<&TooltipState>

Returns the tooltip the chart currently shows.

§Returns
  • Option<&TooltipState> - Some(...) on success, None otherwise.
Source

pub fn hit_test(&self, x: f64, y: f64) -> Option<ChartEvent>

Finds the data point under the given position.

The search walks the chart’s series from the last one to the first, so that the series drawn on top wins — which is what the user expects to click on.

§Arguments
  • f64 - A 64-bit float (f64).
§Returns
  • Option<ChartEvent> - Some(...) on success, None otherwise.
Source

pub fn dispose(&mut self)

Releases the resources the chart holds.

Source

pub fn register_map( &mut self, name: &str, geojson: &DataValue, ) -> Result<&mut Self, GeoError>

Registers a map, so that a series can draw it.

The map is given as a GeoJSON document: a collection of features, each with a geometry and a name. The name of the map is the one a series asks for.

The geometry is kept out of the option on purpose: a map of a country is megabytes of coordinates, and every chart of the application draws the very same one.

§Arguments
  • &str - Shared reference to a str.
  • &DataValue - Shared reference to a DataValue.
§Returns
  • Result<&mut Self, GeoError> - Result of the operation; an Err variant on failure.
Source

pub fn register_map_data(&mut self, data: MapData) -> &mut Self

Registers a map that was built by hand.

§Arguments
  • MapData - A MapData parameter.
§Returns
  • &mut Self - A mut Self value.
Source

pub fn maps(&self) -> &MapRegistry

Returns the maps the chart can draw.

§Returns
  • &MapRegistry - A MapRegistry value.
Source

pub fn map_names(&self) -> Vec<String>

Returns the names of the maps the chart can draw.

§Returns
  • Vec<String> - A Vec<String> value.
Source

pub fn to_data_url(&self) -> Option<String>

Returns the chart as a data URL.

The PNG is produced by the browser, so it is only available in a browser; a native build returns None.

§Returns
  • Option<String> - Some(...) on success, None otherwise.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Chart

§

impl !Send for Chart

§

impl !Sync for Chart

§

impl !UnwindSafe for Chart

§

impl Freeze for Chart

§

impl Unpin for Chart

§

impl UnsafeUnpin 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more