pub struct LineChart { /* private fields */ }Expand description
Line 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, LineChart,
AxisConfig};
let line_chart = LineChart::builder()
.series(vec![
DataSeries::builder()
.name("Website")
.data(data_points(vec![
("Week 1", 32000),
("Week 2", 35000),
("Week 3", 29000),
("Week 4", 41000),
("Week 5", 45000),
])?)
.build()?,
DataSeries::builder()
.name("In-store")
.data(data_points(vec![
("Week 1", 17000),
("Week 2", 20000),
("Week 3", 15000),
("Week 4", 22000),
("Week 5", 30000),
])?)
.build()?,
])
.axis_config(
AxisConfig::builder()
.categories(vec![
"Week 1",
"Week 2",
"Week 3",
"Week 4",
"Week 5",
])
.x_label("Week")
.y_label("Paper Sales (USD)")
.build()?
)
.build()?;
let expected = serde_json::json!({
"type": "line",
"series": [
{
"name": "Website",
"data": [
{ "label": "Week 1", "value": 32000 },
{ "label": "Week 2", "value": 35000 },
{ "label": "Week 3", "value": 29000 },
{ "label": "Week 4", "value": 41000 },
{ "label": "Week 5", "value": 45000 }
]
},
{
"name": "In-store",
"data": [
{ "label": "Week 1", "value": 17000 },
{ "label": "Week 2", "value": 20000 },
{ "label": "Week 3", "value": 15000 },
{ "label": "Week 4", "value": 22000 },
{ "label": "Week 5", "value": 30000 }
]
}
],
"axis_config": {
"categories": [
"Week 1",
"Week 2",
"Week 3",
"Week 4",
"Week 5"
],
"x_label": "Week",
"y_label": "Paper Sales (USD)"
}
});
let json = serde_json::to_value(line_chart).unwrap();
assert_eq!(json, expected);Implementations§
Source§impl LineChart
impl LineChart
Sourcepub fn builder() -> LineChartBuilder
pub fn builder() -> LineChartBuilder
constract LineChartBuilder object.
Trait Implementations§
impl StructuralPartialEq for LineChart
Auto Trait Implementations§
impl Freeze for LineChart
impl RefUnwindSafe for LineChart
impl Send for LineChart
impl Sync for LineChart
impl Unpin for LineChart
impl UnsafeUnpin for LineChart
impl UnwindSafe for LineChart
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