Highchart Legend into another Element (div)

2019-02-21 22:31发布

问题:

i need another Highchart Legend which i want to style with css/html. I found a topic with this topic but I can't get it to work and the jsFiddle Link isn't working anymore...

Can someone help me to get this working? Please

Here is my jsfiddle Link http://jsfiddle.net/chogger/j3xvg

This is what I found:

$(chart.series).each(function(i, serie){
$('<li style="color: '+serie.color+'">'+serie.name+'</li>').click(function(){
    serie.visible ? serie.hide() : serie.show();
}).appendTo('#legend')

})

回答1:

What exactly doesn't work for you? Are you using load event handler for this? See: http://jsfiddle.net/j3xvg/1/

chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container',
        defaultSeriesType: 'line',
        marginRight: 50,
        marginBottom: 175,
        events: {
            load: function () {
                var chart = this;
                $(chart.series).each(function (i, serie) {
                    $('<li style="color: ' + serie.color + '">' + serie.name + '</li>').click(function () {
                        serie.visible ? serie.hide() : serie.show();
                    }).appendTo('#legend');
                });
            }
        }
    },
});