最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - amCharts LabelFunction not working - Stack Overflow

programmeradmin0浏览0评论

/

I'm trying to add a custom label to the end of each bar in a chart, like so:

  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits",
    "labelFunction": function(data) {return 'new label';}
  }],

The labelFunction property isn't working and I'm not sure why.

https://jsfiddle/f3zy3bjc/

I'm trying to add a custom label to the end of each bar in a chart, like so:

  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits",
    "labelFunction": function(data) {return 'new label';}
  }],

The labelFunction property isn't working and I'm not sure why.

Share Improve this question edited Mar 12, 2016 at 18:01 martynasma 8,5952 gold badges32 silver badges47 bronze badges asked Mar 10, 2016 at 21:24 dingdingdingdingdingding 1,5813 gold badges15 silver badges27 bronze badges 1
  • Maybe: enter link description here – Dayane RS Commented Mar 11, 2016 at 1:25
Add a ment  | 

1 Answer 1

Reset to default 10

It's a good question. The reason why it doesn't work is that labelFunction does not event get invoked if there are not label, and there are no label if labelText is not set.

So, as awkward as it may sound, you need to define labelText as well. You can set it to anything, it just need to produce a non-empty string.

  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits",
    "labelText": " ",
    "labelFunction": function(data) {return 'new label';}
  }],

Updated fiddle.

发布评论

评论列表(0)

  1. 暂无评论