forked from yuankunzhang/charming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
large_scale_area.rs
62 lines (59 loc) · 2.13 KB
/
large_scale_area.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
use charming::{
component::{
Axis, DataZoom, DataZoomType, Feature, Restore, SaveAsImage, Title, Toolbox,
ToolboxDataZoom,
},
element::{AreaStyle, AxisType, Color, ColorStop, LineStyle, Symbol, Tooltip, Trigger},
series::Line,
Chart,
};
use chrono::{Days, NaiveDate};
use rand::Rng;
pub fn chart() -> Chart {
let base_date = NaiveDate::parse_from_str("1968-09-03", "%Y-%m-%d").unwrap();
let mut rng = rand::thread_rng();
let mut dates = vec![];
let mut values = vec![rng.gen::<f64>() * 300.];
for i in 1..20001 {
let date = base_date.checked_add_days(Days::new(i)).unwrap();
dates.push(date.format("%Y/%m/%d").to_string());
values.push((rng.gen::<f64>() - 0.5) * 20. + values[(i - 1) as usize]);
}
Chart::new()
.tooltip(Tooltip::new().trigger(Trigger::Axis))
.title(Title::new().left("center").text("Large Area Chart"))
.toolbox(
Toolbox::new().feature(
Feature::new()
.data_zoom(ToolboxDataZoom::new().y_axis_index("none"))
.restore(Restore::new())
.save_as_image(SaveAsImage::new()),
),
)
.x_axis(
Axis::new()
.type_(AxisType::Category)
.boundary_gap(false)
.data(dates),
)
.y_axis(Axis::new().type_(AxisType::Value))
.data_zoom(DataZoom::new().type_(DataZoomType::Inside).start(0).end(10))
.data_zoom(DataZoom::new().start(0).end(10))
.series(
Line::new()
.name("Fake Data")
.symbol(Symbol::None)
.line_style(LineStyle::new().color("rgb(255, 70, 131"))
.area_style(AreaStyle::new().color(Color::LinearGradient {
x: 0.,
y: 0.,
x2: 0.,
y2: 1.,
color_stops: vec![
ColorStop::new(0, "rgb(255, 158, 68)"),
ColorStop::new(1, "rgb(255, 70, 131)"),
],
}))
.data(values),
)
}