Skip to content
프로젝트

소개

Rust로 구현한 Grammar of Graphics입니다.

디자인 및 미디어

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
+3
in 15 days
+7
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

English | 简体中文

Charton

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

Crates.io Documentation Build Status License

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

Grid Lines

Stacked Bar Chart

Stacked Bar Chart

Grouped Bar Chart with Errorbar

Grouped Bar With Errorbar

Density

Density

Histogram

Histogram

Heatmap (continuous)

Heatmap (continuous)

Heatmap

Heatmap

Grouped Boxplot

Grouped Boxplot

Cumulative Frequency

Cumulative Frequency

Distribution

Distribution

Pie

Pie

Donut

Donut

Rose

Rose

Nightingale

Nightingale

Simple Stacked Area

Simple Stack Area

Normalized Stacked Area

Normalized Stacked Area

Steamgraph

Steamgraph

Beeswarm

Beeswarm

Strip

Strip

World map

Geo Chart

Quasirandom

Quasirandom

Grouped Violin

Grouped Violin

Density Contour

Density Contour

Density Heatmap

Density Heatmap

Bump

Bump Chart

Ridgeline

Ridgeline

Dumbbell

Dumbbell

Lollipop

Lollipop

Waterfall

Waterfall

Candlestick

Candlestick

Composition

Composition

Mandelbrot

Mandelbrot

Sierpinski

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_column instead 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.

Facet Grid

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 gui Dashboard

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.

Charton Wasm demo

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:

evcxr jupyter

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.

Comparison 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

NEJM

Charton

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

관련 프로젝트 살펴보기

불러오는 중…