vicanso/charts-rs
Acerca de
Biblioteca de gráficos para Rust.
Datos y análisisWhat you can do
- Graphviz DOT (optional dot feature): pure-Rust, zero-extra-dependency SVG rendering and syntax validation (dot_validate) for directed (digraph) and undirected (graph / neato / circo) graphs, supporting nested clusters, record/Mrecord and HTML <table> ports, CSS/X11/HSV colors, MultiChart embedding, and opt-in safe links (Guide).
- Series: stacked and 100% stacked, bars mixed with lines, two y axes, smooth and step lines, areas, bands and error bars, mark lines, points and areas, regression curves, marginal histograms, density contours, missing values.
- Axes: categories, values, time and logarithmic scales, with titles and label formats.
- Looks: themes, gradients, a legend on any side, labels that keep out of each other's way, SVG animation, hover tooltips, a copyright line or a watermark anywhere on the chart.
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- +3
- in 15 days
- +2
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
Originalcharts-rs
中文 · Gallery · Try it in the browser
Charts, Mermaid & Graphviz DOT for Rust, without a browser. charts-rs renders 31 chart types, MultiChart compositions, 19 Mermaid diagrams (mermaid feature), and Graphviz DOT diagrams (dot feature) as SVG, PNG, JPEG, WebP, or AVIF — from a few lines of Rust or an ECharts-style JSON document.
All 31 chart types, MultiChart, Mermaid & DOT → · Try it in the browser →
▶ Watch 27s showcase video (charts, Mermaid diagrams & theme switching)
https://github.com/user-attachments/assets/104382e7-1279-4fb1-9598-05c98844fff0
Why charts-rs
- Nothing to install but the crate. No headless browser, no Node.js: a chart is a function call that returns SVG. Made for reports, e-mails, bots and dashboards that are rendered on a server.
- Fast. An SVG in well under a millisecond, a PNG in a few milliseconds (benchmark).
- 31 chart types +
MultiChart+ 19 Mermaid diagrams + Graphviz DOT (34 total chart types), from bars, lines and pies to candlesticks, heatmaps, sankey, gantt charts and maps — plus pure-Rust, zero-dependency Mermaid (mermaid) and Graphviz DOT (dot) rendering — and several of them in one picture. - Rust or JSON. A typed API, or a JSON document with the same options. Every key is documented and checked: a typo returns an error with a hint instead of silently ignoring options.
- Built for servers, bots & AI / MCP. Exposes two-tier
(
Essential/Full) JSON Schemas,chart_catalog(), multi-issue validation (validate_chart_json),RenderLimits, named GeoJSON registration (register_geo_json), andllms.txtfor LLM & MCP workflows. - Themes and fonts. Ten themes and your own; your own fonts (TTF, OTF, TTC), Chinese, Japanese and Korean ones included, for the memory of the file.
Quick start
[dependencies]
charts-rs = "2"
use charts_rs::BarChart;
let mut chart = BarChart::new(
vec![
("Email", vec![120.0, 132.0, 101.0, 134.0, 90.0]).into(),
("Search", vec![220.0, 182.0, 191.0, 234.0, 290.0]).into(),
],
["Mon", "Tue", "Wed", "Thu", "Fri"].map(String::from).to_vec(),
);
chart.title.text = "Visits".to_string();
let svg = chart.svg().unwrap();
The same chart from JSON — what a service gets from a request, or a configuration file:
use charts_rs::BarChart;
let chart = BarChart::from_json(
r#"{
"title_text": "Visits",
"x_axis_data": ["Mon", "Tue", "Wed", "Thu", "Fri"],
"series_list": [
{"name": "Email", "data": [120, 132, 101, 134, 90]},
{"name": "Search", "data": [220, 182, 191, 234, 290]}
]
}"#,
)
.unwrap();
let svg = chart.svg().unwrap();
As an image, with the png feature (jpeg, webp and avif are features
of their own):
[dependencies]
charts-rs = { version = "2", features = ["png"] }
use charts_rs::{LineChart, svg_to_png};
let chart = LineChart::from_json(
r#"{
"x_axis_data": ["Mon", "Tue", "Wed"],
"series_list": [{"name": "Email", "data": [120, 132, 101]}]
}"#,
)
.unwrap();
let png = svg_to_png(&chart.svg().unwrap()).unwrap();
std::fs::write("visits.png", png).unwrap();
Or render a Mermaid diagram without a browser (with the mermaid feature; see
Guide):
[dependencies]
charts-rs = { version = "2", features = ["mermaid"] }
# #[cfg(feature = "mermaid")]
# {
use charts_rs::{mermaid_to_svg, mermaid_validate};
let src = "flowchart LR\n A[Client] --> B{Gateway}\n B -->|OK| C[(DB)]";
mermaid_validate(src).unwrap();
let svg = mermaid_to_svg(src).unwrap();
assert!(svg.starts_with("<svg"));
# }
(For untrusted input, MermaidChart::allow_links = false disables SVG <a> links — see the Guide. Graphviz DOT diagrams are also supported via the optional dot feature and dot_to_svg / DotChart — see the Guide.)
Features
- Charts: bar, horizontal bar, line, pie, radar, scatter and bubble,
candlestick, table (with sparklines in its cells), heatmap, funnel,
waterfall, calendar, gauge, treemap, box and violin plot, sunburst, sankey, tree,
graph, parallel, theme river, histogram, polar bar, chord, gantt, map,
lines, bullet, stat (KPI cards), timeline, word cloud — and
MultiChart, which puts several on one canvas, their plots lined up one above the other. - Mermaid (optional
mermaidfeature): pure-Rust, zero-extra-dependency SVG rendering and syntax validation (mermaid_validate) for 19 diagram types (flowchart,sequenceDiagram,stateDiagram,classDiagram,erDiagram,mindmap,quadrantChart,pie,gantt,sankey,xychart,radar,treemap,timeline,packet,kanban,gitGraph,block,architecture). Inherits active themes, composes inMultiChart, and supports rounded orthogonal routing, per-subgraphdirection, frontmatter /%%{init}%%config,accTitle/accDescr, v11 shapes, and Markdown labels (Guide, Design). - Graphviz DOT (optional
dotfeature): pure-Rust, zero-extra-dependency SVG rendering and syntax validation (dot_validate) for directed (digraph) and undirected (graph/neato/circo) graphs, supporting nested clusters,record/Mrecordand HTML<table>ports, CSS/X11/HSV colors,MultiChartembedding, and opt-in safe links (Guide). - Series: stacked and 100% stacked, bars mixed with lines, two y axes, smooth and step lines, areas, bands and error bars, mark lines, points and areas, regression curves, marginal histograms, density contours, missing values.
- Axes: categories, values, time and logarithmic scales, with titles and label formats.
- Looks: themes, gradients, a legend on any side, labels that keep out of each other's way, SVG animation, hover tooltips, a copyright line or a watermark anywhere on the chart.
- Output: SVG — compact on request, 20–30% smaller — and PNG, JPEG, WebP or AVIF at any size.
- Command line:
cargo install charts-rs --features cligives acharts-rsbinary that renders.mmd,.dot/.gv, JSON, and Markdown files (batch rewritingmermaid/dot/graphviz/charts-rsblocks to inline SVG or cached image files, also exposed in Rust viarender_markdown) to SVG/PNG/JPEG/WebP/AVIF with mmdc-style flags (Guide).
Documentation
| Guide | Building charts in Rust and from JSON, axes, labels, fonts, images |
| JSON reference | Every option of every chart: its type, its default, what it does |
| llms.txt | Compact LLM & MCP-ready reference (APIs, schemas, chart catalog, Mermaid spec) |
| llms-full.txt | Full LLM bundle (llms.txt + Guide + JSON reference, built with make llms) |
| Gallery | Every chart type and its variants |
| Mermaid architecture & design | Pure-Rust Mermaid engine architecture, layout engines, and adapter design |
| Themes | The ten built-in themes |
| Maps of China | GeoJSON of the provinces of China and of the cities of each, ready for a MapChart — in the repository, not in the crate |
| Examples | cargo run --example bar, cargo run --example mermaid --features mermaid, cargo run --example showcase --features "mermaid,png", and more runnable examples |
| API docs | The Rust API on docs.rs |
| Changelog | What changed, and how to move from 1.x to 2.0 |
| Web demo | Edit the JSON, see the chart (source) |
Benchmark
The SVG of a chart is generated in well under a millisecond. Turning it into a PNG takes a few milliseconds: parsing the SVG, rasterizing and encoding it. Charts of 600 × 400 pixels, on one thread of an Apple M4 Pro, with Rust 1.99:
| Chart | SVG | PNG, from the SVG |
|---|---|---|
| Bar: 4 series of 7 values, one of them a line, with labels | 41 µs | 1.7 ms |
| Line: 2 series of 100 points, smooth and filled | 158 µs | 3.4 ms |
| Pie: 12 slices | 52 µs | 1.4 ms |
| Sankey: 8 nodes, 10 links | 71 µs | 1.2 ms |
| The bar chart at 1200 × 800 pixels | 41 µs | 3.4 ms |
These are the numbers of cargo bench --features png
(benches/bench.rs), which measures the SVG of more
charts as well. They depend on the machine.
Minimum supported Rust version
charts-rs 2.x builds with Rust 1.88 or newer (edition 2024). The MSRV may rise in a minor release; the change is noted in the changelog.
License
This project is licensed under the Apache-2.0 license.
Explorar proyectos relacionados
Cargando…






