5 releases

0.2.0 Mar 28, 2024
0.1.3 Nov 6, 2023
0.1.2 Jun 3, 2023
0.1.1 Feb 17, 2023
0.1.0 Dec 18, 2022

#68 in WebAssembly

Download history 6/week @ 2024-02-15 16/week @ 2024-02-22 1/week @ 2024-02-29 18/week @ 2024-03-07 19/week @ 2024-03-14 147/week @ 2024-03-28 18/week @ 2024-04-04

188 downloads per month

MIT/Apache

66KB
1.5K SLoC

Discord Server

dioxus-charts 📊

A simple chart components library for Dioxus.

This crate provides some basic SVG-based chart components, customizable with CSS, to be used with the Dioxus GUI library. The components configuration was designed to be similar to what one would find in JavaScript chart libraries.

The components available currently are:

  • PieChart: for Pie, Donut and Gauge charts
  • BarChart: for Bar and Stacked Bar charts, vertical or horizontal
  • LineChart

You can check them out at the very simple demo site for now.

Usage

This crate is on crates.io and can be used by adding dioxus-charts to your dependencies in your project's Cargo.toml.

[dependencies]
dioxus-charts = "0.2"

Example

use dioxus::prelude::*;
use dioxus_charts::BarChart;

fn app() -> Element {
    rsx!(
        BarChart {
            padding_top: 30,
            padding_left: 70,
            padding_right: 50,
            padding_bottom: 30,
            bar_width: "10%",
            horizontal_bars: true,
            label_interpolation: (|v| format!("{v}%")) as fn(f32) -> String,
            series: vec![
                vec![63.0, 14.4, 8.0, 5.1, 1.8],
            ],
            labels: vec!["Chrome".into(), "Safari".into(), "IE/Edge".into(), "Firefox".into(), "Opera".into()]
        }
    )
}

There is also a couple of examples in the examples folder with a Makefile.toml that makes it easier to build them. You need to install cargo-make first to make use of them:

cargo install cargo-make

You will also need to have sass and tailwindcss installed in your system for the make commands to generate the css files.

Then for the desktop demo, inside the examples folder:

cd examples
cargo make desktop

The web example was used to generate the demo site. To test it out yourself you need to have trunk for the dev-server and the rust wasm target installed:

cargo install trunk
rustup target add wasm32-unknown-unknown

Then build and launch the dev-server inside the examples folder:

cargo make web

Note: if you get hit by an error when the web example launches, its possible you were blessed by a version mismatch issue caused by the rustwasm tooling getting out of sync. The simplest fix for that seems to be to just remove the Cargo.lock file from the examples/web folder. Check this issue for more info if that doesn't do it.

Please check out the Dioxus reference guide for more information.

License

Licensed under either of Apache License, Version 2.0 or MIT License at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Dioxus-Charts by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~5–12MB
~127K SLoC