Skip to content

Commit ae66800

Browse files
committed
Add script id for chart html (fixes multiple plots on same page not being displayed)
1 parent ccb6af7 commit ae66800

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: src/Plotly.NET/GenericChart.fs

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module HTML =
5959
newScript.AppendLine("""<div id="[ID]" style="width: [WIDTH]px; height: [HEIGHT]px;"><!-- Plotly chart will be drawn inside this DIV --></div>""") |> ignore
6060
newScript.AppendLine("<script type=\"text/javascript\">") |> ignore
6161
newScript.AppendLine(@"
62-
var renderPlotly = function() {
62+
var renderPlotly_[SCRIPTID] = function() {
6363
var fsharpPlotlyRequire = requirejs.config({context:'fsharp-plotly',paths:{plotly:'https://cdn.plot.ly/plotly-latest.min'}}) || require;
6464
fsharpPlotlyRequire(['plotly'], function(Plotly) {") |> ignore
6565
newScript.AppendLine(@"
@@ -73,12 +73,12 @@ module HTML =
7373
var script = document.createElement("script");
7474
script.setAttribute("src", "https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js");
7575
script.onload = function(){
76-
renderPlotly();
76+
renderPlotly_[SCRIPTID]();
7777
};
7878
document.getElementsByTagName("head")[0].appendChild(script);
7979
}
8080
else {
81-
renderPlotly();
81+
renderPlotly_[SCRIPTID]();
8282
}""") |> ignore
8383
newScript.AppendLine("</script>") |> ignore
8484
newScript.ToString()
@@ -278,6 +278,7 @@ module GenericChart =
278278
.Replace("[WIDTH]", string width)
279279
.Replace("[HEIGHT]", string height)
280280
.Replace("[ID]", guid)
281+
.Replace("[SCRIPTID]", guid.Replace("-",""))
281282
.Replace("[DATA]", tracesJson)
282283
.Replace("[LAYOUT]", layoutJson)
283284
.Replace("[CONFIG]", configJson)

0 commit comments

Comments
 (0)