1+ (**
2+ ---
3+ title: Basics
4+ category: General
5+ categoryindex: 1
6+ index: 2
7+ ---
8+ *)
9+
10+
11+ (* ** hide ***)
12+
13+ (* ** condition: prepare ***)
14+ #r " nuget: Newtonsoft.JSON, 12.0.3"
15+ #r " nuget: PuppeteerSharp"
16+ #r " ../bin/Plotly.NET/netstandard2.0/Plotly.NET.dll"
17+ #r " ../bin/Plotly.NET.ImageExport/netstandard2.0/Plotly.NET.ImageExport.dll"
18+
19+ (* ** condition: ipynb ***)
20+ #if IPYNB
21+ #r " nuget: Plotly.NET, {{fsdocs-package-version}}"
22+ #r " nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
23+ #r " nuget: Plotly.NET.ImageExport, {{fsdocs-package-version}}"
24+ #endif // IPYNB
25+
26+
27+ (**
28+ [ ![ Binder] ( {{root}}img/badge-binder.svg )] ( https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath={{fsdocs-source-basename}}.ipynb ) &emsp ;
29+ [ ![ Script] ( {{root}}img/badge-script.svg )] ( {{root}}{{fsdocs-source-basename}}.fsx ) &emsp ;
30+ [ ![ Notebook] ( {{root}}img/badge-notebook.svg )] ( {{root}}{{fsdocs-source-basename}}.ipynb )
31+
32+ # Static image export
33+
34+ The supported image types are:
35+ - jpg via ` Chart.SaveJPG `
36+ - png via ` Chart.SavePNG `
37+ - svg via ` Chart.SaveSVG `
38+
39+ The parameters for all three functions are exactly the same.
40+ *)
41+
42+ open Plotly.NET
43+ open Plotly.NET .ImageExport
44+
45+ let exampleChart =
46+ Chart.Histogram2dContour(
47+ [ 1. ; 2. ; 2. ; 4. ; 5. ],
48+ [ 1. ; 2. ; 2. ; 4. ; 5. ]
49+ )
50+
51+ (* **do-not-eval***)
52+ exampleChart
53+ |> Chart.saveJPG(
54+ " /your/path/without/extension/here" ,
55+ Width= 300 ,
56+ Height= 300
57+ )
58+
59+ #if IPYNB
60+
61+ let imgString = $""" <img
62+ src= "{exampleChart|> Chart.toBase64JPGString(Width=300,Height=300)}"
63+ />"""
64+
65+ DisplayExtensions.DisplayAs( imgString, " text/html" )
66+
67+ #endif // IPYNB
68+
69+ (* **hide***)
70+ $""" <img
71+ src= "{exampleChart|> Chart.toBase64JPGString(Width=300,Height=300)}"
72+ />"""
73+
74+ (* **include-it-raw***)
75+
76+ (**
77+
78+ *)
79+
80+ let base64JPG =
81+ exampleChart
82+ |> Chart.toBase64PNGString(
83+ Width= 300 ,
84+ Height= 300
85+ )
86+
87+ #if IPYNB
88+
89+ let imgString = $""" <img
90+ src= "{base64JPG}"
91+ />"""
92+
93+ DisplayExtensions.DisplayAs( imgString, " text/html" )
94+
95+ #endif // IPYNB
96+
97+ $""" <img
98+ src= "{base64JPG}"
99+ />"""
100+ (* **include-it-raw***)
101+
102+
103+ (**
104+ *)
105+
106+ let svgString =
107+ exampleChart
108+ |> Chart.toSVGString(
109+ Width= 300 ,
110+ Height= 300
111+ )
112+
113+ #if IPYNB
114+ DisplayExtensions.DisplayAs( svgString, " image/svg+xml" )
115+ #endif // IPYNB
116+
117+ svgString
118+ (* **include-it-raw***)
0 commit comments