Highcharts Legend Title水平对齐

时间:2014-10-06 23:49:37

标签: javascript highcharts

在示例中,图例标题为' City'水平对齐到左边。有没有办法可以将标题水平对齐到图例区域的中心?

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

在上面的图例标题中编辑样式似乎没有做任何事情。

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

感谢。

1 个答案:

答案 0 :(得分:4)

艰难的一个。

我能想到的只是在图表加载上以编程方式进行:

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

更新了fiddle

相关问题