0

I am working with highcharts in scalaJS. I want to create such [ [0, 1],[1, 2],[2, 8] ] JS array in scalaJS (basically 2D array)
What kind of parameters can be passed can be seen in this documentation : HighChart Documentation
Need to override this array to data val of the class (see documentation) How to create 2D array in scala of type specified in the documentation ?
Find a sample project Here(GitHub).

Rupinder Singh
  • 233
  • 4
  • 9

2 Answers2

0
import scala.scalajs.js

val data = js.Array(
  js.Array(0, 1),
  js.Array(1, 2),
  js.Array(2, 8) 
)
  • Gives error : type mismatch `found` : scala.scalajs.js.Array[scala.scalajs.js.Array[Int]] `required` : scala.scalajs.js.UndefOr[scala.scalajs.js.Array[scala.scalajs.js.|[scala.scalajs.js.|[com.highcharts.CleanJsObject[com.highcharts.config.SeriesLineData],scala.scalajs.js.Array[scala.scalajs.js.Any]],Double]]] data = js.Array( @Aleksey Fomkin see documentation for proper required type. – Rupinder Singh Jan 21 '17 at 13:16
0

From the Scaladoc, the expected type of data is:

js.UndefOr[js.Array[CleanJsObject[SeriesLineData] | js.Array[js.Any] | Double]]

That's a pretty awful beast, and the type inference has a hard time figuring it out. You can help the type inference enough like this:

val data: js.UndefOr[js.Array[CleanJsObject[SeriesLineData] | js.Array[js.Any] | Double]] =
  js.defined(js.Array(
      js.Array[js.Any](0, 1),
      js.Array[js.Any](1, 2),
      js.Array[js.Any](2, 8)
  ))
sjrd
  • 21,805
  • 2
  • 61
  • 91
  • Thank you so much ! I can't tell you for how long I was struggling for this , tried so many iteration. I would want to understand docs like that some day. Thank you so much !! @sjrd – Rupinder Singh Jan 22 '17 at 18:31