pub struct BarChart { /* private fields */ }Expand description
Bar chart block representation.
§Fields and Validations
For more details, see the official documentation.
| Field | Type | Required | Validation |
|---|---|---|---|
| series | Vec<DataSeries> | Yes | Min 1, Max 6 items, Unique names, Labels must match axis categories |
| axis_config | AxisConfig | Yes | N/A |
§Example
use slack_messaging::blocks::data_visualization::charts::{data_points, DataSeries, BarChart,
AxisConfig};
let bar_chart = BarChart::builder()
.series(vec![
DataSeries::builder()
.name("Pie")
.data(data_points(vec![
("Strawberry Rhubarb", 85),
("Pumpkin", 70),
("Lemon Meringue", 72),
("Blueberry", 90),
("Key Lime", 56),
])?)
.build()?
])
.axis_config(
AxisConfig::builder()
.categories(vec![
"Strawberry Rhubarb",
"Pumpkin",
"Lemon Meringue",
"Blueberry",
"Key Lime",
])
.x_label("Pies")
.y_label("Percentage of Tastiness")
.build()?
)
.build()?;
let expected = serde_json::json!({
"type": "bar",
"series": [
{
"name": "Pie",
"data": [
{ "label": "Strawberry Rhubarb", "value": 85 },
{ "label": "Pumpkin", "value": 70 },
{ "label": "Lemon Meringue", "value": 72 },
{ "label": "Blueberry", "value": 90 },
{ "label": "Key Lime", "value": 56 }
]
}
],
"axis_config": {
"categories": [
"Strawberry Rhubarb",
"Pumpkin",
"Lemon Meringue",
"Blueberry",
"Key Lime"
],
"x_label": "Pies",
"y_label": "Percentage of Tastiness"
}
});
let json = serde_json::to_value(bar_chart).unwrap();
assert_eq!(json, expected);Implementations§
Source§impl BarChart
impl BarChart
Sourcepub fn builder() -> BarChartBuilder
pub fn builder() -> BarChartBuilder
constract BarChartBuilder object.
Trait Implementations§
impl StructuralPartialEq for BarChart
Auto Trait Implementations§
impl Freeze for BarChart
impl RefUnwindSafe for BarChart
impl Send for BarChart
impl Sync for BarChart
impl Unpin for BarChart
impl UnsafeUnpin for BarChart
impl UnwindSafe for BarChart
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more