-
Notifications
You must be signed in to change notification settings - Fork 9
/
line_with_interval.rs
64 lines (60 loc) · 2.13 KB
/
line_with_interval.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
55
56
57
58
59
60
61
62
63
64
use vega_lite_4::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// The chart
let chart = VegaliteBuilder::default()
.title("Line Chart with Confidence Interval Band")
.height(200.)
.width(300.)
.data(
UrlDataBuilder::default()
.url("https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json")
.build()?,
)
.mark(Mark::Line)
.encoding(
EdEncodingBuilder::default()
.x(XClassBuilder::default()
.field("Year")
.position_def_type(Type::Temporal)
.time_unit(TimeUnit::Year)
.build()?)
.build()?,
)
.layer(vec![
LayerElementBuilder::default()
.mark(Mark::Line)
.encoding(
LayerEncodingBuilder::default()
.y(YClassBuilder::default()
.field("Miles_per_Gallon")
.position_def_type(Type::Quantitative)
.aggregate(NonArgAggregateOp::Mean)
.build()?)
.build()?,
)
.build()?,
LayerElementBuilder::default()
.mark(
DefBuilder::default()
.def_type(Mark::Errorband)
.extent(ExtentExtent::Ci)
.build()?,
)
.encoding(
LayerEncodingBuilder::default()
.y(YClassBuilder::default()
.title("Mean of Miles per Gallon (95% CIs)")
.field("Miles_per_Gallon")
.position_def_type(Type::Quantitative)
.build()?)
.build()?,
)
.build()?,
])
.build()?;
// display the chart using `showata`
chart.show()?;
// print the vega lite spec
eprint!("{}", chart.to_string()?);
Ok(())
}