How can I exclude one specific data point from legend on pie type of chart, but show all others?
0
votes
3 Answers
3
votes
That option currently does not exist in HighCharts that I can find, however, you may be able to do a little hacking of the source code to get it to work.
I used version v2.3.3
for this hack, however, other versions may work similarly.
The code in question is around line 9336:
allItems = [];
each(chart.series, function (serie) {
var seriesOptions = serie.options;
if (!seriesOptions.showInLegend) {
return;
}
// use points or series for the legend item depending on legendType
allItems = allItems.concat(
serie.legendItems ||
(seriesOptions.legendType === 'point' ?
serie.data :
serie)
);
});
Immediately after that code, place the following code:
for (var i=0;i<allItems.length;i++){
if (typeof allItems[i].showInLegend !== "undefined"){
if (!allItems[i].showInLegend){
allItems.splice(i,1)
i--;
}
}
}
Then for the point set showInLegend=false like so:
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true,
showInLegend: false
},
Here is a JSFiddle showing the working concept: http://jsfiddle.net/mkremer90/zXSJW/
0
votes
0
votes
You can use "fake" series, like in this example:
which introduces how to display defined item in legend.
legendItemClick: function (event) {
console.log(this);
var thisSeriesId = this.id;
var thisSeriesVisibility = this.visible ? true : false;
$(chart.series).each(function (i, e) {
$(e.data).each(function(j, k){
if (thisSeriesId === k.id) {
thisSeriesVisibility ? k.setVisible(false) : k.setVisible(true);
}
});
});
event.preventDefault();
}