Struct charming::Chart

source ·
pub struct Chart { /* private fields */ }
Expand description

The chart representation.

Anatomy of a Chart

A chart is a collection of different components, each of which is responsible for rendering a specific part of the chart. Below is a sample chart with a few components:

                   Sales Report
  |                                                        # coffee
30|                  x                                     x juice
  |      @           x             @                       @ milk
20|    # @           x@           x@          #
  |    #x@          #x@          #x@          #x
10|    #x@          #x@          #x@          #x@
  |    #x@          #x@          #x@          #x@
 0+-----------------------------------------------------
       Jan          Feb          Mar          Apr

The chart above has the following components: an x axis, an y axis, a title on the top center, and a legend on the top right.

The creation of charts in Charming is done in a builder-like fashion. Once you get a hang of this pattern, you will find that it is very easy to compose a chart. For instance, the following code snippet shows how to create the chart above:

use charming::Chart;
use charming::component::{Axis, Legend, Title};

let chart = Chart::new()
    .title(Title::new().text("Sales Report"))
    .x_axis(Axis::new().data(vec!["Jan", "Feb", "Mar", "Apr"]))
    .y_axis(Axis::new())
    .legend(Legend::new().data(vec!["coffee", "juice", "milk"]));

Components of a Chart

The following sections describe the components of a chart in detail.

Title

Title is the title of a chart, including main title and subtitle. A chart can have multiple titles, which is useful when you want to show multiple sub- charts in a single chart.

use charming::Chart;
use charming::component::Title;

let chart = Chart::new()
    .title(Title::new().text("Sales Report"));

Legend

Legend is the legend of a chart, which is used to show the meaning of the symbols and colors in the chart. A chart can have multiple legends.

use charming::Chart;
use charming::component::Legend;

let chart = Chart::new()
    .legend(Legend::new().data(vec!["coffee", "juice", "milk"]));

Grid

Grid is the background grid in a cartesian coordinate system. A chart can have multiple grids.

use charming::Chart;
use charming::component::Grid;

let chart = Chart::new()
    .grid(Grid::new());

X Axis and Y Axis

Axis is the axis in a cartesian coordinate system.

use charming::Chart;
use charming::component::Axis;

let chart = Chart::new()
    .x_axis(Axis::new().data(vec!["Jan", "Feb", "Mar", "Apr"]))
    .y_axis(Axis::new());

Polar Coordinate

[Polar] is the polar coordinate system. Polar coordinate can be used in scatter and line charts. Every polar coordinate has an AngleAxis and a RadiusAxis.

Radar Coordinate

RadarCoordinate is the radar coordinate system. Radar coordinate can be in radar charts.

Data Zoom

DataZoom is used for zooming a specific area, which enables user to view data in different scales. A chart can have multiple data zooms.

Visual Map

VisualMap is a visual encoding component. It maps data to visual channels, such as color, symbol size or symbol shape. A chart can have multiple visual maps.

Tooltip

Tooltip is a floating box that appears when user hovers over a data item.

AxisPointer

AxisPointer is a tool for displaying reference line and axis value under mouse pointer.

Toolbox

Toolbox is a feature toolbox that includes data view, save as image, data zoom, restore, and reset.

Implementations§

source§

impl Chart

source

pub fn new() -> Self

source

pub fn title(self, title: Title) -> Self

source

pub fn tooltip(self, tooltip: Tooltip) -> Self

source

pub fn legend(self, legend: Legend) -> Self

source

pub fn toolbox(self, toolbox: Toolbox) -> Self

source

pub fn grid(self, grid: Grid) -> Self

source

pub fn grid3d(self, grid: Grid3D) -> Self

source

pub fn x_axis(self, x_axis: Axis) -> Self

source

pub fn x_axis3d(self, x_axis: Axis3D) -> Self

source

pub fn y_axis(self, y_axis: Axis) -> Self

source

pub fn y_axis3d(self, y_axis: Axis3D) -> Self

source

pub fn z_axis3d(self, z_axis: Axis3D) -> Self

source

pub fn polar(self, polar: PolarCoordinate) -> Self

source

pub fn angle_axis(self, angle_axis: AngleAxis) -> Self

source

pub fn radius_axis(self, radius_axis: RadiusAxis) -> Self

source

pub fn single_axis(self, single_axis: SingleAxis) -> Self

source

pub fn parallel_axis(self, parallel_axis: ParallelAxis) -> Self

source

pub fn axis_pointer(self, axis_pointer: AxisPointer) -> Self

source

pub fn visual_map(self, visual_map: VisualMap) -> Self

source

pub fn data_zoom(self, data_zoom: DataZoom) -> Self

source

pub fn parallel(self, parallel: ParallelCoordinate) -> Self

source

pub fn dataset(self, dataset: Dataset) -> Self

source

pub fn radar(self, radar: RadarCoordinate) -> Self

source

pub fn color(self, color: Vec<Color>) -> Self

source

pub fn background_color<C: Into<Color>>(self, color: C) -> Self

source

pub fn mark_line(self, mark_line: MarkLine) -> Self

source

pub fn aria(self, aria: Aria) -> Self

source

pub fn series<S: Into<Series>>(self, series: S) -> Self

source

pub fn geo_map<M: Into<GeoMap>>(self, map: M) -> Self

source

pub fn save_as_image_type(&self) -> Option<&SaveAsImageType>

Trait Implementations§

source§

impl Serialize for Chart

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl ToString for Chart

source§

fn to_string(&self) -> String

Converts the given value to a String. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Chart

§

impl Send for Chart

§

impl Sync for Chart

§

impl Unpin 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Serializable for T
where T: Serialize,

source§

fn to_v8<'a>( &mut self, scope: &mut HandleScope<'a> ) -> Result<Local<'a, Value>, Error>

source§

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

§

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

§

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.