Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

amCharts LabelFunction not working

https://jsfiddle.net/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.

like image 407
dingdingding Avatar asked Jan 07 '23 11:01

dingdingding


1 Answers

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.

like image 97
martynasma Avatar answered Jan 18 '23 09:01

martynasma