VoidKing
VoidKing

Reputation: 6412

How Can I Hide a Pie Chart's Slice in HighCharts Without Removing It From the Legend?

I've looked everywhere for an answer to this, but I can't seem to figure out what I'm doing wrong here.

I just want to be able to start a pie chart, using HighCharts, with certain slices hidden (as if they had been "clicked" off in the legend).

I've done this in HighStock and it was a simple matter of:

var chart = $("#overallChart").highcharts(); //$("#overallChart") is the div where my HighStock chart is rendered to.
var series = chart.series;

//*****SET DEFAULT STARTING LINES*****//
for (var s = 0; s < series.length; s++) {
    if (s != 1 && s != 2 && s != 3 && s != 4) {
        series[s].hide();
    }
}
//*****set default starting lines*****//

And it works, perfectly.

The problem is, when I try to do this in a highcharts "pie" chart, it doesn't work (doesn't error or anything, simply doesn't work).

I assumed it worked the same way as above, since the documentation shows the same hide() method (as well as the explanation). Highcharts API Reference

Here's my code for the pie chart:

var pieChart = $("#overallPie").highcharts(); //$("#overallPie") is the div where my Highcharts chart is rendered to.
var pieSeries = pieChart.series;

//*****SET DEFAULT STARTING SLICES*****//
for (var p = 0; p < pieSeries.length; p++) {
    if (p != 0 && p != 1) {
        pieSeries[p].hide();
    }
}
//*****set default starting slices*****//

I guess you have to do this differently in a pie chart? I've seen somewhere that you can redraw the pie chart, but is this really necessary?

Upvotes: 2

Views: 4741

Answers (1)

Fizor
Fizor

Reputation: 1530

If I understood your question correctly, you can just use the visible: false on your data series.

See FIDDLE here

Upvotes: 3

Related Questions