Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts Legend Title Horizontal Align

In the example the legend title 'City' is horizontally aligned to the left. Is there a way I can horizontally align the title to the center of the legend area?

    legend: {
        title: {
            text: 'City<br/><span style="font-size: 9px; color: #666; font-weight: normal">(Click to hide)</span>',
            style: {
                fontStyle: 'italic'
            }
        }
    },

Editing the style in legend title above doesn't seem to do anything.

Example: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/legend/title/

Thanks.

like image 248
tenble Avatar asked Sep 29 '22 17:09

tenble


1 Answers

Tough one.

Only thing I can come up with is to do it programmatically on chart load:

function(){
    var legWidth = this.legend.maxItemWidth; // width of legend
    $.each(this.legend.title.element.children[0].children, function(i,j){
        j = $(j); // for each span in title
        var spanWidth = j.width();
        j.attr('dx', (legWidth / 2) - (spanWidth / 2)); // move it to center
    });
}

Updated fiddle.

like image 134
Mark Avatar answered Oct 04 '22 03:10

Mark