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
impl Chart
Sourcepub fn scatter(df: &DataFrame) -> ScatterBuilder<'_>
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()?;Sourcepub fn line(df: &DataFrame) -> LineBuilder<'_>
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()?;Sourcepub fn bar(df: &DataFrame) -> BarBuilder<'_>
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()?;Sourcepub fn histogram(df: &DataFrame) -> HistogramBuilder<'_>
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()?;Sourcepub fn heatmap(df: &DataFrame) -> HeatmapBuilder<'_>
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()?;Sourcepub fn box_plot(df: &DataFrame) -> BoxPlotBuilder<'_>
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()?;Sourcepub fn area(df: &DataFrame) -> AreaBuilder<'_>
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
impl Chart
Sourcepub fn svg(&self) -> &str
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"));Sourcepub fn warnings(&self) -> &[CharcoalWarning]
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}");
}Sourcepub fn width(&self) -> u32
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());Sourcepub fn height(&self) -> u32
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());Sourcepub fn save_svg(&self, path: &str) -> Result<(), CharcoalError>
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")?;Sourcepub fn save_html(&self, path: &str) -> Result<(), CharcoalError>
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")?;Trait Implementations§
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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