Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  168] [ 4]  / answers: 1 / hits: 10567  / 10 Years ago, thu, january 8, 2015, 12:00:00

I'm doing a responsive pie chart which holds title in centered position inside it.I've used,



title: {
text: ,
margin: 0,
y:0,
x:0,
align: 'center',
verticalAlign: 'middle',
},


but it's not perfectly centered inside the chart.Any suggestions would be appreciated.Thank you in advance.



Here's the Link : http://jsfiddle.net/LHSey/128/


More From » highcharts

 Answers
-4

Better is remove title and use renderer which allows to add custom text, which can be repositioned each time (when you redraw chart). Only what you need is catch this event.



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,
},
}


Example: http://jsfiddle.net/LHSey/129/


[#40157] Wednesday, January 7, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jazminkyrap

Total Points: 631
Total Questions: 89
Total Answers: 109

Location: Finland
Member since Fri, Oct 21, 2022
2 Years ago
;