charts-rs
charts-rs is a charting library for rust. It's simple and fast.
Overview
charts-rs provides a straightforward approach to generating charts with support for multiple output formats including svg, png, jpeg, webp, and avif. The library offers ten distinct themes: light, dark, grafana, ant, vintage, walden, westeros, chalk, shine, and shadcn, with light as the default theme.
The library supports seventeen chart types: Bar, HorizontalBar, Line, Pie, Radar, Scatter, Candlestick, Table, Heatmap, Funnel, Waterfall, MultiChart, Calendar, Gauge, Treemap, BoxPlot, and Sunburst. Drawing inspiration from Apache ECharts, charts-rs enables developers to create charts with similar functionality and appearance.
Themes
Features
- Ten built-in themes; custom themes supported via
add_theme() - Custom font loading from ttf or otf files
- Advanced line chart features: smooth curves, area filling, mark points and mark lines
- Multiple legend styles across all charts:
round rect,circle, andrect - Dual y-axis support via
y_axis_configsandseries.y_axis_index - Logarithmic scale support (
"log","log2", or{"type":"log","base":N}) - Gradient fill for bars, areas, and pie slices (
Fill::LinearGradient) - Per-series mixed chart types (bar + line on the same chart)
- Series stacking, dash patterns, and per-bar custom colors
- SVG animation support (duration, easing, stagger) for bar and line charts
- Null / missing data points via
NIL_VALUE(nullin JSON) - JSON-based chart configuration for all chart types
- Multiple output formats: svg, png, jpeg, webp, avif
- Scaled image export via
svg_to_png_with_sizeand equivalent functions - Web-based JSON editor for interactive chart configuration and testing
Demo
You can try to use the web demo page, it's simple and useful.
Charts Web Demo Page: https://charts.npmtrend.com/
Charts Web Source: https://github.com/vicanso/charts-rs-web
Mix line bar
Horizontal bar
Line
Pie
Radar
Scatter
Candlestick
Table
Heatmap
Multi Chart
Example
New from option
use ;
let mut bar_chart = new_with_theme;
bar_chart.title_text = "Mixed Line and Bar".to_string;
bar_chart.legend_margin = Some;
bar_chart.series_list.category = Some;
bar_chart.series_list.y_axis_index = 1;
bar_chart.series_list.label_show = true;
bar_chart
.y_axis_configs
.push;
bar_chart.y_axis_configs.axis_formatter = Some;
bar_chart.y_axis_configs.axis_formatter = Some;
println!;
svg_to_png.unwrap;
From json
use ;
let bar_chart = from_json.unwrap;
println!;
svg_to_png.unwrap;
Scaled image export
use ;
let chart = from_json.unwrap;
let svg = chart.svg.unwrap;
// Scale to exactly 800×400
let png = svg_to_png_with_size.unwrap;
// Scale to width 800, preserve aspect ratio
let png = svg_to_png_with_size.unwrap;
Null data points
Use null in JSON arrays (or NIL_VALUE in Rust) to represent missing data; the chart skips rendering for those positions.
Label formatters
Formatters are supported in series_label_formatter, axis_formatter, and value_formatter (GaugeChart).
| Placeholder | Meaning |
|---|---|
{c} |
Data value |
{a} |
Series name |
{b} |
Category (x-axis label) |
{d} |
Percentage (pie / funnel) |
{t} |
Thousands notation (1.2K, 5.6M) |
Load more fonts
let buf = read.unwrap;
get_or_try_init_fonts;
License
This project is licensed under the Apache-2.0 license.