|
| 1 | +(** |
| 2 | +--- |
| 3 | +title: Layout images |
| 4 | +category: Chart Layout |
| 5 | +categoryindex: 2 |
| 6 | +index: 6 |
| 7 | +--- |
| 8 | +*) |
| 9 | + |
| 10 | +(*** hide ***) |
| 11 | + |
| 12 | +(*** condition: prepare ***) |
| 13 | +#r "nuget: Newtonsoft.JSON, 12.0.3" |
| 14 | +#r "nuget: DynamicObj" |
| 15 | +#r "../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll" |
| 16 | + |
| 17 | +(*** condition: ipynb ***) |
| 18 | +#if IPYNB |
| 19 | +#r "nuget: Plotly.NET, {{fsdocs-package-version}}" |
| 20 | +#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}" |
| 21 | +#endif // IPYNB |
| 22 | + |
| 23 | +(** |
| 24 | +# Annotations |
| 25 | +
|
| 26 | +[](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb)  |
| 27 | +[]({{root}}{{fsdocs-source-basename}}.fsx)  |
| 28 | +[]({{root}}{{fsdocs-source-basename}}.ipynb) |
| 29 | +
|
| 30 | +
|
| 31 | +*Summary:* This example shows how to create Images and add them to the Charts in F#. |
| 32 | +
|
| 33 | +let's first create some data for the purpose of creating example charts: |
| 34 | +
|
| 35 | +*) |
| 36 | + |
| 37 | +open Plotly.NET |
| 38 | + |
| 39 | +let x = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ] |
| 40 | +let y' = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.] |
| 41 | + |
| 42 | +(** |
| 43 | +use the `LayoutImage.init` function to generate an image, and either the `Chart.withLayoutImage` or the `Chart.withLayoutImages` function to add |
| 44 | +multiple annotations at once. |
| 45 | +
|
| 46 | +*) |
| 47 | + |
| 48 | +open Plotly.NET.LayoutObjects |
| 49 | + |
| 50 | +let image = |
| 51 | + LayoutImage.init( |
| 52 | + Source="https://fsharp.org/img/logo/fsharp.svg", |
| 53 | + XRef="x", |
| 54 | + YRef="y", |
| 55 | + X=0, |
| 56 | + Y=3, |
| 57 | + SizeX=2, |
| 58 | + SizeY=2, |
| 59 | + Sizing=StyleParam.LayoutImageSizing.Stretch, |
| 60 | + Opacity=0.5, |
| 61 | + Layer=StyleParam.Layer.Below |
| 62 | + ) |
| 63 | + |
| 64 | +let imageChart = |
| 65 | + Chart.Line(x,y',Name="line") |
| 66 | + |> Chart.withLayoutImage(image) |
| 67 | + |
| 68 | +(*** condition: ipynb ***) |
| 69 | +#if IPYNB |
| 70 | +imageChart |
| 71 | +#endif // IPYNB |
| 72 | + |
| 73 | +(***hide***) |
| 74 | +imageChart |> GenericChart.toChartHTML |
| 75 | +(***include-it-raw***) |
| 76 | + |
0 commit comments