Applying custom formatting logic to PieChart legend values

This demo shows how we can use adapters to apply custom formatting logic to legend labels based on their value.

Code

legend.valueLabels.template.adapters.add("text", function(text, target) {
  if (target.dataItem && (target.dataItem.get("valuePercentTotal") < 5)) {
    return "<5%";
  }
  return text;
});
legend.valueLabels.template.adapters.add("text", function(text, target) {
  if (target.dataItem && (target.dataItem.get("valuePercentTotal") < 5)) {
    return "<5%";
  }
  return text;
});

Example

See the Pen
Applying custom formatting logic to PieChart legend values
by amCharts team (@amcharts)
on CodePen.0

Posted in Uncategorized