正确的coffeescript中的highchart API yAxis标签样式的语法?

时间:2014-05-15 20:49:38

标签: api syntax highcharts coffeescript dashing

Javascript / Coffeescript newb here。我最近在coffeescript中摆弄了一个highcharts双米api。我正在尝试更改标签的样式(即颜色,字体大小)。我查看了高图网站(Highchart API Reference)中的示例,将javascript转换为coffeescript可能有点挑剔。下面的语法似乎不正确,我只是想知道样式标签的正确语法是什么。

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'`

1 个答案:

答案 0 :(得分: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'
     }
    ]
相关问题