2
votes

How do I add 2 legends in one chart? Basically, I just need to display 2 copies of the legend in a stack chart.. http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/legend/labelformatter/

$(function () {
$('#container').highcharts({

    chart: {
    },

    legend: {
        layout: 'vertical',
        backgroundColor: '#FFFFFF',
        floating: true,
        align: 'left',
        verticalAlign: 'top',
        x: 90,
        y: 45,
        labelFormatter: function() {
            return this.name +' (click to hide)';
        }
    },

    xAxis: {
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
    }, {
        data: [95.6, 54.4, 29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1]     
    }]
});

});

1
Which plotting library are you using?Myles Baker
I'm using standard highcharts librarymaximumride

1 Answers

1
votes

The highcharts supports only single legend. If you need additioanl, you should create it as html object, which will call a show/hide functionon series like in the example:

 $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);
    });       

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