格式化Highcharts y轴标签

Dón*_*nal 26 javascript highcharts

我正在使用Highcharts生成一个显示货币值的折线图.默认情况下,y轴标签使用公制前缀作为缩写,例如显示3k而不是3000

我想在这些标签前加一个货币符号,例如显示$ 3k​​而不是3k.但是,只要我添加货币符号,就不再使用指标前缀.我尝试了以下内容

    yAxis: {
        labels: {                
            formatter: function () {
                return '$' + this.value;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

并尝试过

    yAxis: {
        labels: {
            format: '${value}'
        }
    }
Run Code Online (Sandbox Code Playgroud)

但在这两种情况下都会显示$ 3000而不是$ 3k.是否可以添加货币符号而不会丢失指标前缀?

这是一个演示(这里JSFiddle)来说明问题

$(function() {
  $('#container').highcharts({

    yAxis: {
      // if you include the lines below, the metric prefixes disappear
      /*
      labels: {
          format: '${value}'
      }
      */
    },

    series: [{
      data: [15000, 20000, 30000]
    }]

  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px; width: 500px"></div>
Run Code Online (Sandbox Code Playgroud)

Bar*_*ird 44

您可以从格式化程序函数调用原始格式化程序:

$(function () {
    $('#container').highcharts({

        yAxis: {            
            labels: {
                formatter: function () {
                    return '$' + this.axis.defaultLabelFormatter.call(this);
                }            
            }
        },

        series: [{
            data: [15000, 20000, 30000]
        }]

    });
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/x6b0onkp/2/