Expand description
Charming is a powerful and versatile chart rendering library for Rust that leverages the power of Apache Echarts to deliver high-quality data visualization. Built with the Rust programming language, this library aims to provide the Rust ecosystem with an intuitive and effective way to generate and visualize charts, using a declarative and user-friendly API.
§Basic Usage
Refer to the documentation of the Chart struct for how to create a chart
with various components.
Once you create a chart, you can render it into various format. Charming provides three types of renderers:
- HTML renderer:
HtmlRendererrenders a chart into an HTML fragments and offloads the actual rendering to user’s web browser for an interactive, seamless experience. This renderer is useful when you want to render a chart on the client side, e.g., in a web application. - Image renderer:
ImageRendererrenders a chart into an image file. This renderer makes use of an embed deno_core engine to execute the JavaScript code of Echarts and generate an image file. This renderer is disabled by default, and you need to enable thessr(Server-Side Rendering) feature to use it. To render raster images like PNG thessr-rasterfeature must also be enabled. - WASM renderer:
WasmRendererrenders a chart in a WebAssembly runtime. This renderer is disabled by default, and you need to enable thewasmfeature to use it. Note that thewasmfeature andssrfeature are mutually exclusive.
Here is an example of drawing a simple pie chart into an SVG file:
use charming::{
component::Legend,
element::ItemStyle,
series::{Pie, PieRoseType},
Chart, ImageRenderer
};
let chart = Chart::new()
.legend(Legend::new().top("bottom"))
.series(
Pie::new()
.name("Nightingale Chart")
.rose_type(PieRoseType::Radius)
.radius(vec!["50", "250"])
.center(vec!["50%", "50%"])
.item_style(ItemStyle::new().border_radius(8))
.data(vec![
(40.0, "rose 1"),
(38.0, "rose 2"),
(32.0, "rose 3"),
(30.0, "rose 4"),
(28.0, "rose 5"),
(26.0, "rose 6"),
(22.0, "rose 7"),
(18.0, "rose 8"),
]),
);
let mut renderer = ImageRenderer::new(1000, 800);
renderer.save(&chart, "/tmp/nightingale.svg");§Themes
Charming supports a number of themes out of the box. You can use the
theme::Theme enum to specify a theme for your chart. For instance, the
following code snippet shows how to use the Westeros theme:
use charming::{Chart, ImageRenderer};
use charming::theme::Theme;
use charming::component::Title;
ImageRenderer::new(1000, 800).theme(Theme::Westeros).save(
&Chart::new().title(Title::new().text("Westeros")),
"/tmp/westeros.svg",
);Future versions of Charming will support custom themes.
Re-exports§
pub use renderer::*;
Modules§
Macros§
- df
- The
dfmacro can construct a DataFrame. - dim
- The
dimmacro can construct a Vec<Dimension>. - ds
- The
dsmacro can construct a DataSource from an array of mixed datatypes. - dz
- The
dzmacro can construct a DataFrame from mixed data types. - val
- The
valmacro can construct a CompositeValue::Array.
Structs§
- Chart
- The chart representation.