This is a demo tutorial. While there is no step-by-step commentary available (yet), the live demo below is fully functional. Feel free to open it for full source code.
This demo shows how we can use adapters to dynamically color labels and ticks using the color from their slice.
Code
series.ticks.template.adapters.add("stroke", function(stroke, target) { if (target.dataItem) { return target.dataItem.get("slice").get("fill"); } else { return stroke; } }); series.labels.template.adapters.add("fill", function(fill, target) { if (target.dataItem) { return target.dataItem.get("slice").get("fill"); } else { return fill; } });
series.ticks.template.adapters.add("stroke", function(stroke, target) { if (target.dataItem) { return target.dataItem.get("slice").get("fill"); } else { return stroke; } }); series.labels.template.adapters.add("fill", function(fill, target) { if (target.dataItem) { return target.dataItem.get("slice").get("fill"); } else { return fill; } });
Example
See the Pen Coloring pie labels and ticks by slice by amCharts team (@amcharts) on CodePen.