0

Javascript/Coffeescript newb here. I have recently been fiddling with a highcharts dual meter api in coffeescript. I'm trying to change change the style of my labels (i.e. color, font-size). I've looked at examples in the highchart website (Highchart API Reference) by translating javascript to coffeescript can be a bit finicky. The syntax below appears to be incorrect and I was just wondering what's the correct syntax for styling labels.

Coffeescript:

@chart = undefined labels = {0: '0s', 5: '0.5s', 10: '1s', 15: '10s', 20: '20s'}

.

yAxis: [{
      min: 0
      max: 20
      minorTickPosition: 'outside'
      tickPosition: 'outside'
      minorTickLength: 13
      tickLength: 15

      labels: 
        enabled: true
        formatter: -> labels[@value]`
        style:
          'font-size': '20px'
          'color': '#00ff00'`
4

1 回答 1

1

我没有使用过 HighCharts,但我可以帮助使用 Coffeescript 语法。

您链接到的文档中的 CSS 对象在 Coffee 中看起来像这样:

style =
  color: '#6D869F'
  fontWeight: 'bold'

您发布的 yAxis 数组不应该有第一个大括号,需要最后一个方括号。它应该如下所示:

yAxis: [
  min: 0
  max: 20
  minorTickPosition: 'outside'
  tickPosition: 'outside'
  minorTickLength: 13
  tickLength: 15
  labels: 
    enabled: true
    formatter: -> labels[@value]
    style:
      'font-size': '20px'
      'color': '#00ff00'
]

这会给你一个里面有一个对象的数组。

如果你需要一个包含多个对象的数组,你可以使用这个:

yAxis: [
      {
      min: 0
      max: 20
      minorTickPosition: 'outside'
      tickPosition: 'outside'
      minorTickLength: 13
      tickLength: 15
      labels: 
        enabled: true
        formatter: -> labels[@value]
        style:
          'font-size': '20px'
          'color': '#00ff00'
     }
     {
      min: 0
      max: 20
      minorTickPosition: 'outside'
      tickPosition: 'outside'
      minorTickLength: 13
      tickLength: 15
      labels: 
        enabled: true
        formatter: -> labels[@value]
        style:
          'font-size': '20px'
          'color': '#00ff00'
     }
    ]
于 2014-05-15T21:18:59.090 回答