Struct ChartBuilder
pub struct ChartBuilder<'a, 'b, DB>where
DB: DrawingBackend,{ /* private fields */ }Expand description
The helper object to create a chart context, which is used for the high-level figure drawing.
With the help of this object, we can convert a basic drawing area into a chart context, which allows the high-level charting API being used on the drawing area.
See ChartBuilder::on() for more information and examples.
Implementations§
§impl<'a, 'b, DB> ChartBuilder<'a, 'b, DB>where
DB: DrawingBackend,
impl<'a, 'b, DB> ChartBuilder<'a, 'b, DB>where
DB: DrawingBackend,
pub fn on(root: &'a DrawingArea<DB, Shift>) -> ChartBuilder<'a, 'b, DB>
pub fn on(root: &'a DrawingArea<DB, Shift>) -> ChartBuilder<'a, 'b, DB>
Create a chart builder on the given drawing area
root: The root drawing area- Returns: The chart builder object
§Example
use plotters::prelude::*;
let drawing_area = SVGBackend::new("chart_builder_on.svg", (300, 200)).into_drawing_area();
drawing_area.fill(&WHITE).unwrap();
let mut chart_builder = ChartBuilder::on(&drawing_area);
chart_builder.margin(5).set_left_and_bottom_label_area_size(35)
.caption("Figure title or caption", ("Calibri", 20, FontStyle::Italic, &RED).into_text_style(&drawing_area));
let mut chart_context = chart_builder.build_cartesian_2d(0.0..3.8, 0.0..2.8).unwrap();
chart_context.configure_mesh().draw().unwrap();The result is a chart with customized margins, label area sizes, and title:
pub fn margin<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn margin<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the four margins of the chart.
size: The desired size of the four chart margins in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn margin_top<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn margin_top<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the top margin of the chart.
size: The desired size of the margin in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn margin_bottom<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn margin_bottom<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the bottom margin of the chart.
size: The desired size of the margin in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn margin_left<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn margin_left<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the left margin of the chart.
size: The desired size of the margin in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn margin_right<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn margin_right<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the right margin of the chart.
size: The desired size of the margin in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn set_all_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn set_all_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the four label areas of the chart.
size: The desired size of the four label areas in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn set_left_and_bottom_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn set_left_and_bottom_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the left and bottom label areas of the chart.
size: The desired size of the left and bottom label areas in backend units (pixels).
See ChartBuilder::on() for more information and examples.
pub fn x_label_area_size<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn x_label_area_size<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the X label area at the bottom of the chart.
size: The desired size of the X label area in backend units (pixels). If set to 0, the X label area is removed.
See ChartBuilder::on() for more information and examples.
pub fn y_label_area_size<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn y_label_area_size<S>(&mut self, size: S) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the Y label area to the left of the chart.
size: The desired size of the Y label area in backend units (pixels). If set to 0, the Y label area is removed.
See ChartBuilder::on() for more information and examples.
pub fn top_x_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn top_x_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the X label area at the top of the chart.
size: The desired size of the top X label area in backend units (pixels). If set to 0, the top X label area is removed.
See ChartBuilder::on() for more information and examples.
pub fn right_y_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn right_y_label_area_size<S>(
&mut self,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of the Y label area to the right of the chart.
size: The desired size of the Y label area in backend units (pixels). If set to 0, the Y label area to the right is removed.
See ChartBuilder::on() for more information and examples.
pub fn set_label_area_size<S>(
&mut self,
pos: LabelAreaPosition,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
pub fn set_label_area_size<S>(
&mut self,
pos: LabelAreaPosition,
size: S,
) -> &mut ChartBuilder<'a, 'b, DB>where
S: SizeDesc,
Sets the size of a chart label area.
pos: The position of the desired label area to adjustsize: The desired size of the label area in backend units (pixels). If set to 0, the label area is removed.
See ChartBuilder::on() for more information and examples.
pub fn caption<S, Style>(
&mut self,
caption: S,
style: Style,
) -> &mut ChartBuilder<'a, 'b, DB>
pub fn caption<S, Style>( &mut self, caption: S, style: Style, ) -> &mut ChartBuilder<'a, 'b, DB>
Sets the title or caption of the chart.
caption: The caption of the chartstyle: The text style
The title or caption will be centered at the top of the drawing area.
See ChartBuilder::on() for more information and examples.
pub fn build_ranged<'c, X, Y>(
&mut self,
x_spec: X,
y_spec: Y,
) -> Result<ChartContext<'c, DB, Cartesian2d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
X: AsRangedCoord,
Y: AsRangedCoord,
👎Deprecated: build_ranged has been renamed to build_cartesian_2d and is to be removed in the future.
pub fn build_ranged<'c, X, Y>(
&mut self,
x_spec: X,
y_spec: Y,
) -> Result<ChartContext<'c, DB, Cartesian2d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
X: AsRangedCoord,
Y: AsRangedCoord,
build_ranged has been renamed to build_cartesian_2d and is to be removed in the future.This function has been renamed to ChartBuilder::build_cartesian_2d() and is to be removed in the future.
pub fn build_cartesian_2d<'c, X, Y>(
&mut self,
x_spec: X,
y_spec: Y,
) -> Result<ChartContext<'c, DB, Cartesian2d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
X: AsRangedCoord,
Y: AsRangedCoord,
pub fn build_cartesian_2d<'c, X, Y>(
&mut self,
x_spec: X,
y_spec: Y,
) -> Result<ChartContext<'c, DB, Cartesian2d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>where
X: AsRangedCoord,
Y: AsRangedCoord,
Builds a chart with a 2D Cartesian coordinate system.
x_spec: Specifies the X axis range and data propertiesy_spec: Specifies the Y axis range and data properties- Returns: A
ChartContextobject, ready to visualize data.
See ChartBuilder::on() and ChartContext::configure_mesh() for more information and examples.
pub fn build_cartesian_3d<'c, X, Y, Z>(
&mut self,
x_spec: X,
y_spec: Y,
z_spec: Z,
) -> Result<ChartContext<'c, DB, Cartesian3d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType, <Z as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
pub fn build_cartesian_3d<'c, X, Y, Z>( &mut self, x_spec: X, y_spec: Y, z_spec: Z, ) -> Result<ChartContext<'c, DB, Cartesian3d<<X as AsRangedCoord>::CoordDescType, <Y as AsRangedCoord>::CoordDescType, <Z as AsRangedCoord>::CoordDescType>>, DrawingAreaErrorKind<<DB as DrawingBackend>::ErrorType>>
Builds a chart with a 3D Cartesian coordinate system.
x_spec: Specifies the X axis range and data propertiesy_spec: Specifies the Y axis range and data propertiesz_sepc: Specifies the Z axis range and data properties- Returns: A
ChartContextobject, ready to visualize data.
See ChartBuilder::on() and ChartContext::configure_axes() for more information and examples.
Auto Trait Implementations§
impl<'a, 'b, DB> Freeze for ChartBuilder<'a, 'b, DB>
impl<'a, 'b, DB> !RefUnwindSafe for ChartBuilder<'a, 'b, DB>
impl<'a, 'b, DB> !Send for ChartBuilder<'a, 'b, DB>
impl<'a, 'b, DB> !Sync for ChartBuilder<'a, 'b, DB>
impl<'a, 'b, DB> Unpin for ChartBuilder<'a, 'b, DB>
impl<'a, 'b, DB> !UnwindSafe for ChartBuilder<'a, 'b, DB>
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more