Search code examples
anychartanychart-8.2

How to get total number of levels in sunburst chart?


I'm using a sunburst chart and trying to show the total number of levels in chart.title. I have read about Levels and Leaves but I haven't found anything that gives me the total number of levels. Example


Solution

  • To achieve that you'll need to use the tree data traverser: https://api.anychart.com/v8/anychart.data.Traverser. It'll help you go through the data and count the maximum number of levels. Check this sample: https://playground.anychart.com/2iq3nYxu. Please note that counting starts from 0, which means you'll have to add 1 to the value when showing the result (line 22).