dioxus-charts

Crates.iodioxus-charts
lib.rsdioxus-charts
version0.2.0
sourcesrc
created_at2022-12-18 23:06:42.653478
updated_at2024-03-28 22:29:42.627856
descriptionChart components library for Dioxus
homepage
repositoryhttps://github.com/dioxus-community/dioxus-charts
max_upload_size
id740655
size79,163
Marc Espin (marc2332)

documentation

README

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.

Commit count: 29

cargo fmt