-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstacked_bar_chart.rs
54 lines (50 loc) · 1.71 KB
/
stacked_bar_chart.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use vega_lite_4::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// the chart
let chart = VegaliteBuilder::default()
.title("Weather in Seattle")
.data(
UrlDataBuilder::default()
.url("https://raw.githubusercontent.com/vega/vega-datasets/master/data/seattle-weather.csv")
.build()?
)
.mark(Mark::Bar)
.encoding(
EdEncodingBuilder::default()
.x(XClassBuilder::default()
.field("date")
.time_unit(TimeUnit::Month)
.position_def_type(Type::Ordinal)
.title("Month of the year")
.build()?)
.y(YClassBuilder::default()
.aggregate(NonArgAggregateOp::Count)
.build()?)
.color(ColorClassBuilder::default()
.field("weather")
.scale(ScaleBuilder::default()
.domain([
"sun",
"fog",
"drizzle",
"rain",
"snow",
])
.range([
"#e7ba52",
"#c7c7c7",
"#aec7e8",
"#1f77b4",
"#9467bd",
])
.build()?)
.build()?)
.build()?,
)
.build()?;
// display the chart using `showata`
chart.show()?;
// print the vega lite spec
eprint!("{}", chart.to_string()?);
Ok(())
}