使用ScalaJS的PlotlyJS:3D图形/ WebGL问题

时间:2019-05-14 18:53:09

标签: scala.js plotly.js scalajs-bundler scalably-typed

使用普通的Javascript即可:

 var data = [{
          "z": [[8.83, 8.89, 8.81, 8.87, 8.9, 8.87], [8.89, 8.94, 8.85, 8.94, 8.96, 8.92], ..., [8.93, 8.97, 8.97, 9.18, 9.2, 9.18]],
          "type": "surface"
        }];
 var layout = {};
 var TESTER = document.getElementById('example');
 Plotly.newPlot(TESTER, data, layout);

使用 ScalaJS 无效(显示:您的浏览器不支持WebGL )。我拿了生成的代码,唯一的区别是这一行:

$i_plotly$002ejs.newPlot(TESTER, data, layout)

版本也应该相同:

// JavaScript
<script src="https://cdn.plot.ly/plotly-1.47.2.min.js"></script>

// build.sbt
libraryDependencies ++= Seq(ScalablyTyped.P.`plotly_dot_js`)
npmDependencies in Compile ++= Seq("plotly.js" -> "1.47.2")

这里是Scala代码,我如何使用Plotly

import typings.plotlyDotJsLib.plotlyDotJsMod.{Data, Layout, ^ => Plotly}
...

   val data: js.Array[Data] = js.Array(
  dynLit(
    z =  js.Array(
      js.Array(8.83,8.89,8.81,8.87,8.9,8.87),
      ...
      js.Array(9,9.01,9,9.2,9.23,9.2),
      js.Array(8.99,8.99,8.98,9.18,9.2,9.19),
      js.Array(8.93,8.97,8.97,9.18,9.2,9.18)
  ),
    `type` = "surface"
  ).asInstanceOf[Partial[Data]]
)
...
  Plotly.newPlot("plotCube", data, layout)

0 个答案:

没有答案