wangjiawen2013/charton
À propos
Grammar of Graphics en Rust.
Design et médiasProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- +3
- in 15 days
- +7
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalCharton
A declarative plotting engine for Rust, the shell, and AI agents.
"Really nice project. ... This works perfectly as an ecosystem." — Ritchie Vink, Creator of Polars
Chart like You Mean It
standard blocks — limitless charts
Charton is a high-performance plotting engine that brings a grammar of graphics to Rust, the shell, and AI agents. Describe a chart in Rust code, as a JSON document, from the command line, in a Nushell pipeline, or through an MCP tool call — and render it to SVG, PNG, or PDF, or draw it inline in the terminal. Every interface shares the same chart model, scales, and styling, so a chart looks the same no matter where you build it.
Its API is inspired by Altair, with Polars for fast data processing. It also runs in Jupyter through evcxr_jupyter, in the browser through WebAssembly, and on the GPU through wgpu.
Grid Lines |
Stacked Bar Chart |
Grouped Bar With Errorbar |
Density |
Histogram |
Heatmap (continuous) |
Heatmap |
Grouped Boxplot |
Cumulative Frequency |
Distribution |
Pie |
Donut |
Rose |
Nightingale |
Simple Stack Area |
Normalized Stacked Area |
Steamgraph |
Beeswarm |
Strip |
Geo Chart |
Quasirandom |
Grouped Violin |
Density Contour |
Density Heatmap |
Bump Chart |
Ridgeline |
Dumbbell |
Lollipop |
Waterfall |
Candlestick |
Composition |
![]() Mandelbrot |
![]() Sierpinski |
Quick start
Choose how you want to use Charton:
| Interface | Best for | Get started |
|---|---|---|
| Rust library | Rust developers | cargo add charton |
| Command line | Shell and automation | Charton CLI |
| Nushell plugin | Nushell pipeline charts | Nushell plugin |
| MCP server | AI agents | Charton CLI |
The examples below draw a simple scatter plot to show each interface in use.
Rust library
use charton::prelude::*;
let x = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let y = vec![2.1, 3.2, 3.8, 5.1, 5.9, 7.2];
chart!(x, y)?
.mark_point()?
.encode((alt::x("x"), alt::y("y")))?
.save("scatter.svg")?;
The chart! macro is the shortest path. For production pipelines, use Chart::build with a Dataset or a Polars DataFrame.
Command line
charton plot points.csv --mark point --x x --y y -o scatter.svg
charton plot points.csv --mark point --x x --y y --inline
A single static binary with plot, render, validate, schema, and mcp.
It reads CSV, TSV, NDJSON, or stdin — no Rust toolchain, Node, or Python. Add
--inline to draw the chart in the terminal instead of writing a file;
--inline-style picks halfblock, iterm2, kitty, or sixel.
How to install it (a prebuilt binary for Linux x64, Windows x64 and Apple Silicon,
or cargo install charton-cli) and the full flag reference are in the
CLI README.
Nushell plugin
open points.csv | charton point -x x -y y -o scatter.svg
open points.csv | charton point -x x -y y
The first command saves an image; the second draws it in the terminal.
How to install it (a prebuilt binary, or cargo install nu_plugin_charton), the
plugin add step and the command reference are in the plugin
README; it is built against Nushell 0.117, and its
compatibility table says which
release to use.
MCP server
Point your MCP client at the directory the server is allowed to work in:
{
"mcpServers": {
"charton": {
"command": "charton",
"args": ["mcp", "--root", "/home/you/data"]
}
}
}
Pi reads this entry from .pi/mcp.json in the project (or
~/.pi/agent/mcp.json for every project); Claude Code and other clients use the
same mcpServers shape. Once connected, the agent has seven tools to profile
the data, write a chart document, validate it, and render it — without running
generated code. Add --allow-write if it should also save documents. The tool
and protocol reference is in the CLI
README.
The Rust library
The quick start above shows the smallest possible chart. The rest of this section covers the Rust API in more depth.
Feature flags
Enable only what you need:
[dependencies]
charton = "0.9" # Standard (Single-threaded + SVG export)
charton = { version = "0.9", features = ["png"] } # PNG export on the CPU (no GPU required)
charton = { version = "0.9", features = ["pdf"] } # Export charts to PDF format
charton = { version = "0.9", features = ["wgpu", "png"] } # Local Desktop with GPU acceleration + PNG export
charton = { version = "0.9", features = ["wgpu"] } # Web Browsers (WebAssembly/Wasm target)
charton = { version = "0.9", features = ["parallel"] } # Multi-threaded data processing (Rayon)
charton = { version = "0.9", features = ["geo"] } # Enable geospatial coordinate support
charton = { version = "0.9", features = ["spec"] } # JSON chart documents (the format used by the CLI/MCP)
charton = { version = "0.9", features = ["arrow"] } # Apache Arrow RecordBatch ingestion
charton = { version = "0.9", features = ["terminal"] } # Terminal protocols (pair with "png" to rasterize a chart)
From macros to production API
While the chart! macro is a convenient syntactic sugar for rapid prototyping and simple scripts, the underlying Chart::build API is recommended for production environments where explicit data handling is required.
1. Professional Build API
For complex applications, use Chart::build to gain full control over the Dataset lifecycle.
let ds = Dataset::new()
.with_column("x", x)?
.with_column("y", y)?;
Chart::build(ds)? // Equivalent to chart!(ds)?
.mark_point()?
.encode((alt::x("x"), alt::y("y")))?
.save("scatter.svg")?;
Tip: Use
add_columninstead if you need to add columns dynamically within loops or conditional logic.
2. Polars Integration
For Polars users, Charton provides the load_polars_df! macro to seamlessly convert a DataFrame into a Charton-ready Dataset.
use polars::prelude::*;
let df = df![
"x" => vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
"y" => vec![2.1, 3.2, 3.8, 5.1, 5.9, 7.2]
]?;
// Efficiently convert Polars DataFrame to Charton Dataset
let ds = load_polars_df!(df)?;
Chart::build(ds)? // Equivalent to chart!(ds)?
.mark_point()?
.encode((alt::x("x"), alt::y("y")))?
.save("scatter.svg")?;
Compatibility Note: Charton uses versioned macros to handle Polars' rapid API evolutions. Versions below 0.44 are no longer supported. The standard macro is tested against Polars 0.53, 0.54, and 0.55.
| Polars Version | Macro to Use | Status |
|---|---|---|
| 0.53+ (incl. 0.54/0.55) | load_polars_df!(df)? |
Latest (Standard) |
| 0.44 - 0.52 | load_polars_v44_52!(df)? |
Legacy Support |
| < 0.44 | N/A | Unsupported |
Layered Grammar
Inspired by the Grammar of Graphics (as seen in ggplot2 and Altair), Charton replaces rigid templates with a modular, layer-based system. Visualizations are constructed by stacking atomic marks, offering infinite flexibility beyond fixed chart types.
// Create individual layers
let line = chart!(x, y)?
.mark_line()?
.encode((alt::x("x"), alt::y("y")))?;
let point = chart!(x, y)?
.mark_point()?
.encode((alt::x("x"), alt::y("y")))?;
// Combine into a composite chart
line.and(point).save("layered.svg")?;
Faceting Support
Now supporting multi-panel faceting (wrap and grid layouts), enabling you to easily split and compare complex datasets across coordinated subplots.
Desktop GUI Integration
Charton can render directly into native desktop applications with GPU acceleration. Below is a real-time system telemetry dashboard built with Charton and egui, demonstrating live CPU, memory, swap, and network monitoring with per-core load distribution:
Charton offers two integration paths for GUI applications: render_to_surface for zero-copy GPU rendering in a 60 FPS loop, or the standalone WgpuRenderer when you need to avoid wgpu version conflicts between crates.
WebAssembly and Frontend
Charton supports WebAssembly and modern web frontends. Below is an interactive demo that simulates a 50,000-point Lorenz Attractor at 60 FPS, demonstrating how WebAssembly enables high-performance, real-time data visualization in the browser.
The SVG it returns is a semantic document: elements carry role classes (charton-axis, charton-mark, charton-legend, …) and identity attributes, so a page stylesheet can restyle a chart — dark mode, brand colors, print — without re-rendering it, and screen readers get the chart's title and description instead of a stream of tick numbers. Exported PDFs carry the equivalent structure as tags. See Semantic Output.
Interactive Notebooks (Jupyter)
Charton integrates with evcxr_jupyter for interactive data exploration. Replacing .save() with .show() renders SVGs directly within notebook cells:

True Layer Synchronization
Stop fighting with fragile, hard-coded patches. Charton treats scaling as a Single Source of Truth, making it possible to combine heterogeneous data sources into one plot while maintaining total mathematical consistency across every mark and axis.
This figure demonstrates semantic synchronization in Charton. Point samples and bar backgrounds from different data sources are anchored to a unified scale, ensuring absolute color and spatial consistency.
Publish Quality
Designed for precision, Charton provides pixel-perfect control over complex marks. Whether it is a multi-layered ErrorBar for biomedical research or a high-density scatter plot for finance, Charton delivers the aesthetic rigor required by top-tier journals.
![]() NEJM |
Charton |
A reproduction of Figure 1A from the 2021 NEJM landmark study on once-weekly semaglutide for weight management, implemented using Charton.
Documentation
Please go to the Charton Docs for full documentation.
Other Rust plotting libraries
kuva: A scientific plotting library in Rust. 64 plot types, SVG output, optional PNG/PDF backends, and a CLI binary that renders plots directly from the shell.
charts-rs: An ECharts-inspired Rust charting library with multiple chart types, built-in themes, SVG animations, and multi-format export—tailored for dashboards and web-style visualizations rather than scientific plotting.
License
Charton is licensed under the Apache License 2.0.
AI Declaration
- AI used: Yes
- Role: Implementation acceleration, test generation, documentation
- Human responsibility: Grammar of Graphics architecture design, code review, maintenance, and all project decisions
Explorer des projets similaires
Chargement…


