Skip to content

Commit 27e4c8a

Browse files
committed
fix rendering of financial charts
1 parent e228676 commit 27e4c8a

File tree

5 files changed

+95
-378
lines changed

5 files changed

+95
-378
lines changed

.github/workflows/book.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
cd ${{ github.workspace }}/examples/basic_charts && cargo run
2222
cd ${{ github.workspace }}/examples/statistical_charts && cargo run
2323
cd ${{ github.workspace }}/examples/scientific_charts && cargo run
24+
cd ${{ github.workspace }}/examples/financial_charts && cargo run
2425
- run: mdbook build docs/book
2526
- name: Checkout gh-pages branch
2627
run: |

docs/book/src/recipes/financial_charts/candlestick_charts.md

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The following imports have been used to produce the plots below:
44

5-
```rust
5+
```rust,no_run
66
use plotly::common::{TickFormatStop, Title};
77
use plotly::layout::{Axis, RangeSelector, RangeSlider, SelectorButton, SelectorStep, StepMode};
88
use plotly::{Candlestick, Layout, Ohlc, Plot, Scatter};
@@ -14,87 +14,8 @@ use std::path::PathBuf;
1414
The `to_inline_html` method is used to produce the html plot displayed in this page.
1515

1616
## Simple Candlestick Chart
17-
```rust
18-
fn simple_candlestick_chart(show: bool) {
19-
let x = vec![
20-
"2017-01-04",
21-
"2017-01-05",
22-
"2017-01-06",
23-
"2017-01-09",
24-
"2017-01-10",
25-
"2017-01-11",
26-
"2017-01-12",
27-
"2017-01-13",
28-
"2017-01-17",
29-
"2017-01-18",
30-
"2017-01-19",
31-
"2017-01-20",
32-
"2017-01-23",
33-
"2017-01-24",
34-
"2017-01-25",
35-
"2017-01-26",
36-
"2017-01-27",
37-
"2017-01-30",
38-
"2017-01-31",
39-
"2017-02-01",
40-
"2017-02-02",
41-
"2017-02-03",
42-
"2017-02-06",
43-
"2017-02-07",
44-
"2017-02-08",
45-
"2017-02-09",
46-
"2017-02-10",
47-
"2017-02-13",
48-
"2017-02-14",
49-
"2017-02-15",
50-
];
51-
let open = vec![
52-
115.849998, 115.919998, 116.779999, 117.949997, 118.769997, 118.739998, 118.900002,
53-
119.110001, 118.339996, 120.0, 119.400002, 120.449997, 120.0, 119.550003, 120.419998,
54-
121.669998, 122.139999, 120.93, 121.150002, 127.029999, 127.980003, 128.309998, 129.130005,
55-
130.539993, 131.350006, 131.649994, 132.460007, 133.080002, 133.470001, 135.520004,
56-
];
57-
let high = vec![
58-
116.510002, 116.860001, 118.160004, 119.43, 119.379997, 119.93, 119.300003, 119.620003,
59-
120.239998, 120.5, 120.089996, 120.449997, 120.809998, 120.099998, 122.099998, 122.440002,
60-
122.349998, 121.629997, 121.389999, 130.490005, 129.389999, 129.190002, 130.5, 132.089996,
61-
132.220001, 132.449997, 132.940002, 133.820007, 135.089996, 136.270004,
62-
];
63-
let low = vec![
64-
115.75, 115.809998, 116.470001, 117.940002, 118.300003, 118.599998, 118.209999, 118.809998,
65-
118.220001, 119.709999, 119.370003, 119.730003, 119.769997, 119.5, 120.279999, 121.599998,
66-
121.599998, 120.660004, 120.620003, 127.010002, 127.779999, 128.160004, 128.899994,
67-
130.449997, 131.220001, 131.119995, 132.050003, 132.75, 133.25, 134.619995,
68-
];
69-
let close = vec![
70-
116.019997, 116.610001, 117.910004, 118.989998, 119.110001, 119.75, 119.25, 119.040001,
71-
120.0, 119.989998, 119.779999, 120.0, 120.080002, 119.970001, 121.879997, 121.940002,
72-
121.949997, 121.629997, 121.349998, 128.75, 128.529999, 129.080002, 130.289993, 131.529999,
73-
132.039993, 132.419998, 132.119995, 133.289993, 135.020004, 135.509995,
74-
];
75-
76-
let trace1 = Candlestick::new(x, open, high, low, close);
77-
78-
let mut plot = Plot::new();
79-
plot.add_trace(trace1);
80-
if show {
81-
plot.show();
82-
}
83-
println!(
84-
"{}",
85-
plot.to_inline_html(Some("simple_candlestick_chart"))
86-
);
87-
}
17+
```rust,no_run
18+
{{#include ../../../../../examples/financial_charts/src/main.rs:simple_candlestick_chart}}
8819
```
89-
<div id="simple_candlestick_chart" class="plotly-graph-div" style="height:100%; width:100%;"></div>
90-
<script type="text/javascript">
91-
window.PLOTLYENV=window.PLOTLYENV || {};
92-
if (document.getElementById("simple_candlestick_chart")) {
93-
var d3 = Plotly.d3;
94-
var image_element= d3.select('#image-export');
95-
var trace_0 = {"type":"candlestick","x":["2017-01-04","2017-01-05","2017-01-06","2017-01-09","2017-01-10","2017-01-11","2017-01-12","2017-01-13","2017-01-17","2017-01-18","2017-01-19","2017-01-20","2017-01-23","2017-01-24","2017-01-25","2017-01-26","2017-01-27","2017-01-30","2017-01-31","2017-02-01","2017-02-02","2017-02-03","2017-02-06","2017-02-07","2017-02-08","2017-02-09","2017-02-10","2017-02-13","2017-02-14","2017-02-15"],"open":[115.849998,115.919998,116.779999,117.949997,118.769997,118.739998,118.900002,119.110001,118.339996,120.0,119.400002,120.449997,120.0,119.550003,120.419998,121.669998,122.139999,120.93,121.150002,127.029999,127.980003,128.309998,129.130005,130.539993,131.350006,131.649994,132.460007,133.080002,133.470001,135.520004],"high":[116.510002,116.860001,118.160004,119.43,119.379997,119.93,119.300003,119.620003,120.239998,120.5,120.089996,120.449997,120.809998,120.099998,122.099998,122.440002,122.349998,121.629997,121.389999,130.490005,129.389999,129.190002,130.5,132.089996,132.220001,132.449997,132.940002,133.820007,135.089996,136.270004],"low":[115.75,115.809998,116.470001,117.940002,118.300003,118.599998,118.209999,118.809998,118.220001,119.709999,119.370003,119.730003,119.769997,119.5,120.279999,121.599998,121.599998,120.660004,120.620003,127.010002,127.779999,128.160004,128.899994,130.449997,131.220001,131.119995,132.050003,132.75,133.25,134.619995],"close":[116.019997,116.610001,117.910004,118.989998,119.110001,119.75,119.25,119.040001,120.0,119.989998,119.779999,120.0,120.080002,119.970001,121.879997,121.940002,121.949997,121.629997,121.349998,128.75,128.529999,129.080002,130.289993,131.529999,132.039993,132.419998,132.119995,133.289993,135.020004,135.509995],"increasing":{"line":{"width":1.0,"color":"green"}},"decreasing":{"line":{"width":1.0,"color":"red"}}};
96-
var data = [trace_0];
97-
var layout = {};
98-
Plotly.newPlot('simple_candlestick_chart', data, layout, {"responsive": true});
99-
};
100-
</script>
20+
21+
{{#include ../../../../../examples/financial_charts/out/simple_candlestick_chart.html}}

docs/book/src/recipes/financial_charts/ohlc_charts.md

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The following imports have been used to produce the plots below:
44

5-
```rust
5+
```rust,no_run
66
use plotly::common::{TickFormatStop, Title};
77
use plotly::layout::{Axis, RangeSelector, RangeSlider, SelectorButton, SelectorStep, StepMode};
88
use plotly::{Candlestick, Layout, Ohlc, Plot, Scatter};
@@ -14,87 +14,8 @@ use std::path::PathBuf;
1414
The `to_inline_html` method is used to produce the html plot displayed in this page.
1515

1616
## Simple OHLC Chart
17-
```rust
18-
fn simple_ohlc_chart(show: bool) {
19-
let x = vec![
20-
"2017-01-04",
21-
"2017-01-05",
22-
"2017-01-06",
23-
"2017-01-09",
24-
"2017-01-10",
25-
"2017-01-11",
26-
"2017-01-12",
27-
"2017-01-13",
28-
"2017-01-17",
29-
"2017-01-18",
30-
"2017-01-19",
31-
"2017-01-20",
32-
"2017-01-23",
33-
"2017-01-24",
34-
"2017-01-25",
35-
"2017-01-26",
36-
"2017-01-27",
37-
"2017-01-30",
38-
"2017-01-31",
39-
"2017-02-01",
40-
"2017-02-02",
41-
"2017-02-03",
42-
"2017-02-06",
43-
"2017-02-07",
44-
"2017-02-08",
45-
"2017-02-09",
46-
"2017-02-10",
47-
"2017-02-13",
48-
"2017-02-14",
49-
"2017-02-15",
50-
];
51-
let open = vec![
52-
115.849998, 115.919998, 116.779999, 117.949997, 118.769997, 118.739998, 118.900002,
53-
119.110001, 118.339996, 120.0, 119.400002, 120.449997, 120.0, 119.550003, 120.419998,
54-
121.669998, 122.139999, 120.93, 121.150002, 127.029999, 127.980003, 128.309998, 129.130005,
55-
130.539993, 131.350006, 131.649994, 132.460007, 133.080002, 133.470001, 135.520004,
56-
];
57-
let high = vec![
58-
116.510002, 116.860001, 118.160004, 119.43, 119.379997, 119.93, 119.300003, 119.620003,
59-
120.239998, 120.5, 120.089996, 120.449997, 120.809998, 120.099998, 122.099998, 122.440002,
60-
122.349998, 121.629997, 121.389999, 130.490005, 129.389999, 129.190002, 130.5, 132.089996,
61-
132.220001, 132.449997, 132.940002, 133.820007, 135.089996, 136.270004,
62-
];
63-
let low = vec![
64-
115.75, 115.809998, 116.470001, 117.940002, 118.300003, 118.599998, 118.209999, 118.809998,
65-
118.220001, 119.709999, 119.370003, 119.730003, 119.769997, 119.5, 120.279999, 121.599998,
66-
121.599998, 120.660004, 120.620003, 127.010002, 127.779999, 128.160004, 128.899994,
67-
130.449997, 131.220001, 131.119995, 132.050003, 132.75, 133.25, 134.619995,
68-
];
69-
let close = vec![
70-
116.019997, 116.610001, 117.910004, 118.989998, 119.110001, 119.75, 119.25, 119.040001,
71-
120.0, 119.989998, 119.779999, 120.0, 120.080002, 119.970001, 121.879997, 121.940002,
72-
121.949997, 121.629997, 121.349998, 128.75, 128.529999, 129.080002, 130.289993, 131.529999,
73-
132.039993, 132.419998, 132.119995, 133.289993, 135.020004, 135.509995,
74-
];
75-
76-
let trace1 = Ohlc::new(x, open, high, low, close);
77-
78-
let mut plot = Plot::new();
79-
plot.add_trace(trace1);
80-
if show {
81-
plot.show();
82-
}
83-
println!(
84-
"{}",
85-
plot.to_inline_html(Some("simple_ohlc_chart"))
86-
);
87-
}
17+
```rust,no_run
18+
{{#include ../../../../../examples/financial_charts/src/main.rs:simple_ohlc_chart}}
8819
```
89-
<div id="simple_ohlc_chart" class="plotly-graph-div" style="height:100%; width:100%;"></div>
90-
<script type="text/javascript">
91-
window.PLOTLYENV=window.PLOTLYENV || {};
92-
if (document.getElementById("simple_ohlc_chart")) {
93-
var d3 = Plotly.d3;
94-
var image_element= d3.select('#image-export');
95-
var trace_0 = {"type":"ohlc","x":["2017-01-04","2017-01-05","2017-01-06","2017-01-09","2017-01-10","2017-01-11","2017-01-12","2017-01-13","2017-01-17","2017-01-18","2017-01-19","2017-01-20","2017-01-23","2017-01-24","2017-01-25","2017-01-26","2017-01-27","2017-01-30","2017-01-31","2017-02-01","2017-02-02","2017-02-03","2017-02-06","2017-02-07","2017-02-08","2017-02-09","2017-02-10","2017-02-13","2017-02-14","2017-02-15"],"open":[115.849998,115.919998,116.779999,117.949997,118.769997,118.739998,118.900002,119.110001,118.339996,120.0,119.400002,120.449997,120.0,119.550003,120.419998,121.669998,122.139999,120.93,121.150002,127.029999,127.980003,128.309998,129.130005,130.539993,131.350006,131.649994,132.460007,133.080002,133.470001,135.520004],"high":[116.510002,116.860001,118.160004,119.43,119.379997,119.93,119.300003,119.620003,120.239998,120.5,120.089996,120.449997,120.809998,120.099998,122.099998,122.440002,122.349998,121.629997,121.389999,130.490005,129.389999,129.190002,130.5,132.089996,132.220001,132.449997,132.940002,133.820007,135.089996,136.270004],"low":[115.75,115.809998,116.470001,117.940002,118.300003,118.599998,118.209999,118.809998,118.220001,119.709999,119.370003,119.730003,119.769997,119.5,120.279999,121.599998,121.599998,120.660004,120.620003,127.010002,127.779999,128.160004,128.899994,130.449997,131.220001,131.119995,132.050003,132.75,133.25,134.619995],"close":[116.019997,116.610001,117.910004,118.989998,119.110001,119.75,119.25,119.040001,120.0,119.989998,119.779999,120.0,120.080002,119.970001,121.879997,121.940002,121.949997,121.629997,121.349998,128.75,128.529999,129.080002,130.289993,131.529999,132.039993,132.419998,132.119995,133.289993,135.020004,135.509995],"increasing":{"line":{"width":2.0,"color":"green"}},"decreasing":{"line":{"width":2.0,"color":"red"}}};
96-
var data = [trace_0];
97-
var layout = {};
98-
Plotly.newPlot('simple_ohlc_chart', data, layout, {"responsive": true});
99-
};
100-
</script>
20+
21+
{{#include ../../../../../examples/financial_charts/out/simple_ohlc_chart.html}}

0 commit comments

Comments
 (0)