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 AprThe 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
PolarCoordinate 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
impl Chart
pub fn new() -> Chart
pub fn title<T: Into<Title>>(self, title: T) -> Self
pub fn animation<A: Into<bool>>(self, animation: A) -> Self
pub fn animation_duration<A: Into<AnimationTime>>( self, animation_duration: A, ) -> Self
pub fn animation_threshold<A: Into<f64>>(self, animation_threshold: A) -> Self
pub fn animation_easing<A: Into<Easing>>(self, animation_easing: A) -> Self
pub fn animation_delay<A: Into<AnimationTime>>(self, animation_delay: A) -> Self
pub fn animation_duration_update<A: Into<AnimationTime>>( self, animation_duration_update: A, ) -> Self
pub fn animation_easing_update<A: Into<Easing>>( self, animation_easing_update: A, ) -> Self
pub fn animation_delay_update<A: Into<AnimationTime>>( self, animation_delay_update: A, ) -> Self
pub fn tooltip<T: Into<Tooltip>>(self, tooltip: T) -> Self
pub fn legend<L: Into<LegendConfig>>(self, legend: L) -> Self
pub fn toolbox<T: Into<Toolbox>>(self, toolbox: T) -> Self
pub fn grid<G: Into<Grid>>(self, grid: G) -> Self
pub fn grid3d<G: Into<Grid3D>>(self, grid3d: G) -> Self
pub fn x_axis<X: Into<Axis>>(self, x_axis: X) -> Self
pub fn x_axis3d<X: Into<Axis3D>>(self, x_axis3d: X) -> Self
pub fn y_axis<Y: Into<Axis>>(self, y_axis: Y) -> Self
pub fn y_axis3d<Y: Into<Axis3D>>(self, y_axis3d: Y) -> Self
pub fn z_axis3d<Z: Into<Axis3D>>(self, z_axis3d: Z) -> Self
pub fn polar<P: Into<PolarCoordinate>>(self, polar: P) -> Self
pub fn angle_axis<A: Into<AngleAxis>>(self, angle_axis: A) -> Self
pub fn radius_axis<R: Into<RadiusAxis>>(self, radius_axis: R) -> Self
pub fn single_axis<S: Into<SingleAxis>>(self, single_axis: S) -> Self
pub fn parallel_axis<P: Into<ParallelAxis>>(self, parallel_axis: P) -> Self
pub fn axis_pointer<A: Into<AxisPointer>>(self, axis_pointer: A) -> Self
pub fn visual_map<V: Into<VisualMap>>(self, visual_map: V) -> Self
pub fn data_zoom<D: Into<DataZoom>>(self, data_zoom: D) -> Self
pub fn parallel<P: Into<ParallelCoordinate>>(self, parallel: P) -> Self
pub fn calendar<C: Into<Calendar>>(self, calendar: C) -> Self
pub fn dataset<D: Into<Dataset>>(self, dataset: D) -> Self
pub fn radar<R: Into<RadarCoordinate>>(self, radar: R) -> Self
pub fn color<C: Into<Color>>(self, color: Vec<C>) -> Self
pub fn background_color<B: Into<Color>>(self, background_color: B) -> Self
pub fn mark_line<M: Into<MarkLine>>(self, mark_line: M) -> Self
pub fn aria<A: Into<Aria>>(self, aria: A) -> Self
pub fn series<S: Into<Series>>(self, series: S) -> Self
pub fn geo_map<G: Into<GeoMap>>(self, geo_map: G) -> Self
Source§impl Chart
impl Chart
pub fn save_as_image_type(&self) -> Option<&SaveAsImageType>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chart
impl<'de> Deserialize<'de> for Chart
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Chart
Auto Trait Implementations§
impl Freeze for Chart
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.