Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Place text in center of pie chart - Highcharts
- text = chart.renderer.text("My Text").add();
- textBBox = text.getBBox();
- x = chart.plotLeft + (chart.plotWidth * 0.5) - (textBBox.width * 0.5);
- y = chart.plotTop + (chart.plotHeight * 0.5) - (textBBox.height * 0.5);
- text.attr({x: x, y: y});
- y = chart.plotTop + (chart.plotHeight * 0.5) + (textBBox.height * 0.25);
- var textX = chart.plotLeft + (chart.plotWidth * 0.5);
- var textY = chart.plotTop + (chart.plotHeight * 0.5);
- // The width and height need to be calculated properly, so I made it a span.
- var span = '<span id="pieChartInfoText" style="position:absolute; text-align:center;">';
- span += '<span style="font-size: 32px">Upper</span><br>';
- span += '<span style="font-size: 16px">Lower</span>';
- span += '</span>';
- $("#addText").append(span);
- span = $('#pieChartInfoText');
- span.css('left', textX + (span.width() * -0.5));
- span.css('top', textY + (span.height() * -0.5));
- <div id="container" style="height: 400px; width: 500px"></div>
Advertisement
Add Comment
Please, Sign In to add comment