Skip to content

Commit f1e873d

Browse files
committed
sankey and candlestick charts added
1 parent 0dfae71 commit f1e873d

File tree

9 files changed

+514
-68
lines changed

9 files changed

+514
-68
lines changed

.config/dotnet-tools.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"fake-cli": {
6+
"version": "5.19.0",
7+
"commands": [
8+
"fake"
9+
]
10+
}
11+
}
12+
}

.paket/Paket.Restore.targets

Lines changed: 112 additions & 66 deletions
Large diffs are not rendered by default.

FSharp.Plotly.sln

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
# Visual Studio 15
3-
VisualStudioVersion = 15.0.27703.2000
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29613.14
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{63297B98-5CED-492C-A5B7-A5B4F73CF142}"
66
ProjectSection(SolutionItems) = preProject
@@ -36,6 +36,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
3636
docsrc\content\bar-charts.fsx = docsrc\content\bar-charts.fsx
3737
docsrc\content\box-plots.fsx = docsrc\content\box-plots.fsx
3838
docsrc\content\bubble-charts.fsx = docsrc\content\bubble-charts.fsx
39+
docsrc\content\candlestick.fsx = docsrc\content\candlestick.fsx
3940
docsrc\content\choropleth-map.fsx = docsrc\content\choropleth-map.fsx
4041
docsrc\content\contour-plots.fsx = docsrc\content\contour-plots.fsx
4142
docsrc\content\errorbars.fsx = docsrc\content\errorbars.fsx
@@ -51,6 +52,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
5152
docsrc\content\plotly-wpf.fsx = docsrc\content\plotly-wpf.fsx
5253
docsrc\content\polar-charts.fsx = docsrc\content\polar-charts.fsx
5354
docsrc\content\range-plots.fsx = docsrc\content\range-plots.fsx
55+
docsrc\content\sankey.fsx = docsrc\content\sankey.fsx
5456
docsrc\content\shapes.fsx = docsrc\content\shapes.fsx
5557
docsrc\content\splom.fsx = docsrc\content\splom.fsx
5658
docsrc\content\violin-plots.fsx = docsrc\content\violin-plots.fsx

docsrc/content/candlestick.fsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(*** hide ***)
2+
#r "netstandard"
3+
#r @"../../lib/Formatting/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Candlestick Charts
7+
8+
*Summary:* This example shows how to create candlestick charts in F#.
9+
10+
A candlestick chart is useful for plotting stock prices over time. A candle
11+
is a group of high, open, close and low values over a period of time, e.g. 1 minute, 5 minute, hour, day, etc..
12+
The x-axis is usually dateime values and y is a sequence of candle structures.
13+
*)
14+
15+
open FSharp.Plotly
16+
open FSharp.Plotly.StyleParam
17+
18+
let candles =
19+
[|("2020-01-17T13:40:00", 0.68888, 0.68888, 0.68879, 0.6888);
20+
("2020-01-17T13:41:00", 0.68883, 0.68884, 0.68875, 0.68877);
21+
("2020-01-17T13:42:00", 0.68878, 0.68889, 0.68878, 0.68886);
22+
("2020-01-17T13:43:00", 0.68886, 0.68886, 0.68876, 0.68879);
23+
("2020-01-17T13:44:00", 0.68879, 0.68879, 0.68873, 0.68874);
24+
("2020-01-17T13:45:00", 0.68875, 0.68877, 0.68867, 0.68868);
25+
("2020-01-17T13:46:00", 0.68869, 0.68887, 0.68869, 0.68883);
26+
("2020-01-17T13:47:00", 0.68883, 0.68899, 0.68883, 0.68899);
27+
("2020-01-17T13:48:00", 0.68898, 0.689, 0.68885, 0.68889);
28+
("2020-01-17T13:49:00", 0.68889, 0.68893, 0.68881, 0.68893);
29+
("2020-01-17T13:50:00", 0.68891, 0.68896, 0.68886, 0.68891);
30+
|]
31+
|> Array.map (fun (d,o,h,l,c)->System.DateTime.Parse d, Candle.Create(o,h,l,c))
32+
33+
34+
let ch1 = candles |> Chart.Candelstick
35+
36+
37+
(***do-not-eval***)
38+
ch1 |> Chart.Show
39+
40+
(*** include-value:ch1 ***)
41+
42+

docsrc/content/sankey.fsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(*** hide ***)
2+
#r "netstandard"
3+
#r @"../../lib/Formatting/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Sankey Charts
7+
8+
*Summary:* This example shows how to create sankey charts in F#.
9+
10+
Sankey charts are a visualization of multiple, linked graphs layed out linearly.
11+
These are usually used to depict flow between nodes or stations.
12+
To create Sankey, a set of nodes and links between them are required.
13+
These are created using the provided Node and Link structures.
14+
*)
15+
16+
open FSharp.Plotly
17+
open FSharp.Plotly.StyleParam
18+
let n1 = Node.Create("a",color="Black")
19+
let n2 = Node.Create("b",color="Red")
20+
let n3 = Node.Create("c",color="Purple")
21+
let n4 = Node.Create("d",color="Green")
22+
let n5 = Node.Create("e",color="Orange")
23+
let link1 = Link.Create(n1,n2,value=1.0)
24+
let link2 = Link.Create(n2,n3,value=2.0)
25+
let link3 = Link.Create(n1,n5,value=1.3)
26+
let link4 = Link.Create(n4,n5,value=1.5)
27+
let link5 = Link.Create(n3,n5,value=0.5)
28+
29+
let ch1 =
30+
Chart.Sankey([n1;n2;n3;n4;n5],[link1;link2;link3;link4;link5])
31+
|> Chart.withTitle "Sankey Sample"
32+
33+
34+
(***do-not-eval***)
35+
ch1 |> Chart.Show
36+
37+
(*** include-value:ch1 ***)
38+

lib/Formatting/FSharp.Plotly.dll

35 KB
Binary file not shown.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
namespace FSharp.Plotly
2+
3+
open Trace
4+
open System
5+
6+
type Candle =
7+
{
8+
High : float
9+
Low : float
10+
Close : float
11+
Open : float
12+
}
13+
with
14+
static member Create(o,h,l,c) =
15+
{
16+
High = h
17+
Low = l
18+
Close = c
19+
Open = o
20+
}
21+
22+
[<AutoOpen>]
23+
module CandelstickExtension =
24+
25+
module Trace =
26+
let initCandelstick (applyStyle:Trace->Trace) =
27+
FSharp.Plotly.Trace("candlestick") |> applyStyle
28+
29+
30+
type TraceStyle with
31+
static member Candlestick
32+
(
33+
data : (#IConvertible*Candle) seq,
34+
?increasing : Line,
35+
?decreasing : Line,
36+
?line : Line
37+
) =
38+
(fun (trace:('T :> Trace)) ->
39+
DynObj.setValue trace "open" (data |> Seq.map snd |> Seq.map(fun x->x.Open))
40+
DynObj.setValue trace "high" (data |> Seq.map snd |> Seq.map(fun x->x.High))
41+
DynObj.setValue trace "low" (data |> Seq.map snd |> Seq.map(fun x->x.Low))
42+
DynObj.setValue trace "close" (data |> Seq.map snd |> Seq.map(fun x->x.Close))
43+
DynObj.setValue trace "x" (data |> Seq.map fst)
44+
DynObj.setValue trace "xaxis" "x"
45+
DynObj.setValue trace "yaxis" "y"
46+
DynObj.setValueOpt trace "line" line
47+
DynObj.setValueOpt trace "increasing" increasing
48+
DynObj.setValueOpt trace "decreasing" decreasing
49+
trace
50+
)
51+
52+
type Chart with
53+
static member Candelstick
54+
(
55+
data : (#IConvertible*Candle) seq,
56+
?increasing : Line,
57+
?decreasing : Line,
58+
?line : Line
59+
) =
60+
Trace.initCandelstick(TraceStyle.Candlestick
61+
(
62+
data,
63+
?increasing=increasing,
64+
?decreasing=decreasing,
65+
?line=line
66+
))
67+
|> GenericChart.ofTraceObject

src/FSharp.Plotly/FSharp.Plotly.fsproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
<Compile Include="GenericChart.fs" />
3737
<Compile Include="Chart.fs" />
3838
<Compile Include="ChartExtensions.fs" />
39+
<Compile Include="CandelstickExtension.fs" />
40+
<Compile Include="SankeyExtension.fs" />
3941
<None Include="TestScript.fsx" />
4042
<None Include="paket.references" />
4143
<None Include="paket.template" />

0 commit comments

Comments
 (0)