Skip to main content

Crate charcoal

Crate charcoal 

Source
Expand description

A declarative, DataFrame-native chart library for Polars.

charcoal turns a Polars polars::frame::DataFrame into a publication-quality SVG, standalone HTML, or PNG with a single builder chain — no browser, no Python, no C FFI.

§Feature Flags

FeatureEnablesExtra dependency
(default)SVG and HTML output
staticChart::save_png via pure-Rust resvgresvg
notebook[Chart::display] inline in evcxr Jupyterevcxr_runtime

§Quickstart

use charcoal::{Chart, Theme};
use polars::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let df = CsvReader::from_path("iris.csv")?.finish()?;

    let chart = Chart::scatter(&df)
        .x("sepal_length")
        .y("sepal_width")
        .color_by("species")
        .title("Iris Dataset")
        .theme(Theme::Default)
        .build()?;

    chart.save_html("iris.html")?;
    Ok(())
}

§Examples

Runnable examples for every chart type live in the examples/ directory:

cargo run --example scatter_iris
cargo run --example line_timeseries
cargo run --example bar_categorical
cargo run --example histogram_distribution
cargo run --example heatmap_correlation
cargo run --example box_plot_groups
cargo run --example area_stacked

§Notebook Usage

To display charts inline in an evcxr Jupyter notebook, enable the notebook feature:

[dependencies]
charcoal = { version = "0.1", features = ["notebook"] }

In your first notebook cell, load the dependency:

:dep charcoal = { version = "0.1", features = ["notebook"] }
use charcoal::Chart;

Then call .display() as the last expression in any subsequent cell:

let chart = Chart::scatter(&df).x("x").y("y").build()?;
chart.display();

§Repository

https://github.com/your-handle/charcoal

Structs§

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

Enums§

BinMethod
Strategy used to choose the number of histogram bins.
CharcoalError
Errors that can be returned by charcoal’s public API.
CharcoalWarning
Non-fatal diagnostics attached to a successfully-built crate::Chart.
ColorScale
Continuous color gradient used to encode numeric values in heatmaps.
DashStyle
Dash style for line and area series.
FillMode
Controls the baseline of the filled area.
NullPolicy
How null y-values are handled in connected series (Line, Area).
Orientation
Bar chart orientation.
PointDisplay
Controls which individual data points are rendered on top of each box.
Theme
Overall visual style applied to a chart.