Skip to main content

Chart

Struct Chart 

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

The fully-rendered output of a .build() call.

A Chart is produced by calling .build() at the end of any builder chain. From it you can retrieve the SVG string, write output files, or inspect warnings emitted during rendering.

§Examples

use charcoal::Chart;
let chart = Chart::scatter(&df)
    .x("sepal_length")
    .y("sepal_width")
    .build()?;
chart.save_svg("iris.svg")?;
chart.save_html("iris.html")?;

Implementations§

Source§

impl Chart

Source

pub fn scatter(df: &DataFrame) -> ScatterBuilder<'_>

Begin building a scatter chart from df.

Required columns: .x() (Numeric or Temporal) and .y() (Numeric).

§Examples
use charcoal::Chart;
let chart = Chart::scatter(&df)
    .x("sepal_length")
    .y("sepal_width")
    .color_by("species")
    .build()?;
Source

pub fn line(df: &DataFrame) -> LineBuilder<'_>

Begin building a line chart from df.

Required columns: .x() (Numeric or Temporal) and .y() (Numeric).

§Examples
use charcoal::{Chart, NullPolicy};
let chart = Chart::line(&df)
    .x("date")
    .y("value")
    .null_policy(NullPolicy::Skip)
    .build()?;
Source

pub fn bar(df: &DataFrame) -> BarBuilder<'_>

Begin building a bar chart from df.

Required columns: .x() (Categorical) and .y() (Numeric).

§Examples
use charcoal::Chart;
let chart = Chart::bar(&df)
    .x("category")
    .y("count")
    .build()?;
Source

pub fn histogram(df: &DataFrame) -> HistogramBuilder<'_>

Begin building a histogram from df.

Required column: .x() (Numeric). Bin counts are computed automatically.

§Examples
use charcoal::Chart;
let chart = Chart::histogram(&df)
    .x("value")
    .bins(20)
    .build()?;
Source

pub fn heatmap(df: &DataFrame) -> HeatmapBuilder<'_>

Begin building a heatmap from df.

Required columns: .x() (Categorical), .y() (Categorical), .z() (Numeric).

§Examples
use charcoal::{Chart, ColorScale};
let chart = Chart::heatmap(&df)
    .x("col_label")
    .y("row_label")
    .z("value")
    .color_scale(ColorScale::Viridis)
    .build()?;
Source

pub fn box_plot(df: &DataFrame) -> BoxPlotBuilder<'_>

Begin building a box plot from df.

Required columns: .x() (Categorical, group labels) and .y() (Numeric, values to summarise).

§Examples
use charcoal::Chart;
let chart = Chart::box_plot(&df)
    .x("group")
    .y("measurement")
    .notched(true)
    .build()?;
Source

pub fn area(df: &DataFrame) -> AreaBuilder<'_>

Begin building an area chart from df.

Required columns: .x() (Numeric or Temporal) and .y() (Numeric).

§Examples
use charcoal::{Chart};
use charcoal::FillMode;
let chart = Chart::area(&df)
    .x("week")
    .y("downloads")
    .fill_mode(FillMode::ToZero)
    .build()?;
Source§

impl Chart

Source

pub fn svg(&self) -> &str

The rendered SVG string.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
let svg: &str = chart.svg();
assert!(svg.starts_with("<svg"));
Source

pub fn warnings(&self) -> &[CharcoalWarning]

Warnings accumulated during rendering. Empty slice means a clean build.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
for w in chart.warnings() {
    eprintln!("warning: {w}");
}
Source

pub fn width(&self) -> u32

Chart width in pixels.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
println!("{}×{}", chart.width(), chart.height());
Source

pub fn height(&self) -> u32

Chart height in pixels.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
println!("{}×{}", chart.width(), chart.height());
Source

pub fn save_svg(&self, path: &str) -> Result<(), CharcoalError>

Write the SVG to path (UTF-8, overwrites if exists).

§Errors

CharcoalError::Io if the path is not writable or its parent directory does not exist.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
chart.save_svg("output.svg")?;
Source

pub fn save_html(&self, path: &str) -> Result<(), CharcoalError>

Write an HTML document embedding the SVG inline to path.

The file has no external dependencies and can be opened directly in any browser.

§Errors

CharcoalError::Io if the path is not writable or its parent directory does not exist.

§Examples
let chart = Chart::scatter(&df).x("x").y("y").build()?;
chart.save_html("output.html")?;
Source

pub fn save_png(&self, _path: &str) -> Result<(), CharcoalError>

save_png is only available with the static feature.

Add features = ["static"] to your charcoal dependency in Cargo.toml.

Trait Implementations§

Source§

impl Clone for Chart

Source§

fn clone(&self) -> Chart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Chart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Chart

§

impl RefUnwindSafe for Chart

§

impl Send for Chart

§

impl Sync for Chart

§

impl Unpin for Chart

§

impl UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V