Currently, on enabling the legend of sunburst chart in Highcharts, single series label is seen in legend. Refer following JSFiddle: http://jsfiddle.net/amrutaJgtp/7r8eb5ms/6/
Highcharts pie chart legend shows the all the category labels in the legend. Refer following Pie chart legend: http://jsfiddle.net/amrutaJgtp/wgaak302/
series: [{
name: 'Sales',
colorByPoint: true,
showInLegend: true,
data: [{
name: 'Consumer',
y: 2455
}, {
name: 'Corporate',
y: 6802
},{
name: 'Home office',
y: 9031
}, {
name: 'Small Business',
y: 5551
}]
}]
Is it possible to show all the data points of the sunburst series or atleast the categories - Consumer, Corporate, Home Office, Small Business in legend?
In my opinion the answer is no.
Please refer to this demo: http://jsfiddle.net/kkulig/u3p1usz9/
I tried to implement this functionality by setting
legendType = 'point'
(not docummented in the API, but it works) and overwritingH.Legend.prototype.getAllItems
, but it seems that hiding points is not supported for sunburst. There's no method that will do it - check out theconsole.log
output. Switching visibility of the point by usingvisible
property doesn't work either. Legend behaves properly, but there's no effect on the plot area.Workaround
This simple example shows how to mimic desired legend behavior: http://jsfiddle.net/kkulig/kn10kb7L/
First I added additional two series that have no data:
The color of the legend item markers needs to be handled manually by setting the color of the 'fake' series. I created
visible
flag for every leaf for controlling its visibility. Then I used theirlegendItemClick
callback function to filter the full data set and performsetData
on the first series using the filtered data.API reference: https://api.highcharts.com/highcharts/plotOptions.sunburst.point.events.legendItemClick
If you think that hiding points should be implemented in sunburst series you can share this idea here: https://highcharts.uservoice.com/forums/55896-highcharts-javascript-api
Update
If you want an animation to happen use
addPoint
andremovePoint
instead ofsetData
.API references: