【发布时间】:2016-12-06 02:07:47
【问题描述】:
我正在使用带有 Highcharts 外观的 scala.js (v0.6.13),我遇到了一个障碍,试图访问一些我通常会使用 'this' 和 'chart' 在 javascript 中访问的变量。这是一个例子:
咖啡脚本:
tooltip: {
enabled: true,
positioner: (labelWidth, labelHeight, point) ->
return { x: chart.plotWidth - labelWidth + chart.plotLeft, y: 17 }
formatter: () ->
x = this.x
point = this.points.find (p) -> x == p.x
...
我的问题是如何在 scala.js 的格式化程序和定位器函数中访问“this.x”和“chart.plotWidth”?到目前为止,这是我的 scala 代码:
override val tooltip: Cfg[Tooltip] = Tooltip(
formatter = { () =>
"what?"
}: js.Function0[String],
positioner = { (labelWidth: Any, labelHeight: Any, point: Object) =>
js.Dynamic.literal(
x = labelWidth,
y = 17)
}: js.Function3[Any, Any, Object, Object]
)
编辑:图表属于高图表。
【问题讨论】:
-
您可能想指出您的原始 sn-p 是用 CoffeeScript 而不是 JavaScript 编写的,因此不熟悉 CoffeeScript 的 Scala.js 读者不会完全混淆。
标签: highcharts scala.js