Scala.js联合类型

时间:2016-12-06 22:09:25

标签: scala highcharts scala.js

我正在使用Scala.js的HighCharts外观(v0.6.13),并且在我的图表上配置十字线时遇到了困难。当我看到Scala.js联合类型声明:

时,是我的理解吗?
val crosshair: UndefOr[|[Boolean, CleanJsObject[YAxisCrosshair]]]

十字准线可以是布尔值还是YAxisCrosshair?

如果是这样,我的crosshair设置为true的声明会正确编译:

override val yAxis: Cfg[YAxis] = YAxis(
  gridLineWidth = 0,
  minorGridLineWidth = 0,
  opposite = false,
  labels = YAxisLabels(
    align = "right",
    format = "{value:.8f}"
  ),
  crosshair = true
) 

但是当我将十字准线设置为YAxisCrosshair时,我的项目无法编译。

override val yAxis: Cfg[YAxis] = YAxis(
  gridLineWidth = 0,
  minorGridLineWidth = 0,
  opposite = false,
  labels = YAxisLabels(
    align = "right",
    format = "{value:.8f}"
  ),
  crosshair = YAxisCrosshair(
    snap = false,
    label = YAxisCrosshairLabel(
      format = "{value:.8f}"
    )
  )
)

后面的结果是:

type mismatch;
  found   : com.highstock.config.YAxisCrosshair
  required: scala.scalajs.js.UndefOr[scala.scalajs.js.|        [Boolean,com.highcharts.CleanJsObject[com.highstock.config.YAxisCrosshair]]]

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

我想我找到了答案。这是需要做的事情:

override val yAxis: Cfg[YAxis] = YAxis(
  gridLineWidth = 0,
  minorGridLineWidth = 0,
  opposite = false,
  labels = YAxisLabels(
    align = "right",
    format = "{value:.8f}"
  ),
  crosshair = YAxisCrosshair(
    snap = false,
    label = YAxisCrosshairLabel(
      format = "{value:.8f}"
    )
  ): CleanJsObject[YAxisCrosshair]
)