如何在highcharts的饼图中动态居中图表标题位置

Aru*_*run 3 javascript alignment title highcharts pie-chart

我正在做一个响应式饼图,其中标题位于其中的居中位置。我用过,

title: {
            text: "",
            margin: 0,
            y:0,
            x:0,
            align: 'center',
            verticalAlign: 'middle',
        },
Run Code Online (Sandbox Code Playgroud)

但它并没有完全在图表内居中。任何建议将不胜感激。提前致谢。

这是链接:http : //jsfiddle.net/LHSey/128/

Seb*_*han 5

更好的是删除标题并使用允许添加自定义文本的渲染器,每次都可以重新定位(重绘图表时)。只有你需要的是捕捉这个事件。

function addTitle() {

        if (this.title) {
            this.title.destroy();
        }

        var r = this.renderer,
            x = this.series[0].center[0] + this.plotLeft,
            y = this.series[0].center[1] + this.plotTop;
        this.title = r.text('Series 1', 0, 0)
            .css({
            color: '#4572A7',
            fontSize: '16px'
        }).hide()
            .add();

        var bbox = this.title.getBBox();
        this.title.attr({
            x: x - (bbox.width / 2),
            y: y
        }).show();
    }

chart:{
    events: {
                    load: addTitle,
                    redraw: addTitle,
            },
} 
Run Code Online (Sandbox Code Playgroud)

示例:http : //jsfiddle.net/LHSey/129/