Search code examples
highchartsdotnethighcharts

Pie chart legend shows empty values


Using dot net highcharts and the label formatter to only display certain items in the legend, it displays values that have been returned as ''.

.SetLegend(new Legend { Enabled = true, LabelFormatter = "function() { if (this.y >= 5) { return this.name; } else { return ''; } }"  })

Legend display


Solution

  • You can disable default legend and create your own as HTML. Then you can control which point should be or not displayed.

    Example: http://jsfiddle.net/N3KAC/1/

    $legend = $('#customLegend');
    
        $.each(chart.series[0].data, function (j, data) {
    
            $legend.append('<div class="item"><div class="symbol" style="background-color:'+data.color+'"></div><div class="serieName" id="">' + data.name + '</div></div>');
    
        });
    
        $('#customLegend .item').click(function(){
            var inx = $(this).index(),
                point = chart.series[0].data[inx];
    
            if(point.visible)
                point.setVisible(false);
            else
                point.setVisible(true);
        });