Guest User

Untitled

a guest
Apr 20th, 2012
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Place text in center of pie chart - Highcharts
  2. text = chart.renderer.text("My Text").add();
  3. textBBox = text.getBBox();
  4. x = chart.plotLeft + (chart.plotWidth * 0.5) - (textBBox.width * 0.5);
  5. y = chart.plotTop + (chart.plotHeight * 0.5) - (textBBox.height * 0.5);
  6. text.attr({x: x, y: y});
  7.  
  8. y = chart.plotTop + (chart.plotHeight * 0.5) + (textBBox.height * 0.25);
  9.  
  10. var textX = chart.plotLeft + (chart.plotWidth * 0.5);
  11. var textY = chart.plotTop + (chart.plotHeight * 0.5);
  12.  
  13. // The width and height need to be calculated properly, so I made it a span.
  14. var span = '<span id="pieChartInfoText" style="position:absolute; text-align:center;">';
  15. span += '<span style="font-size: 32px">Upper</span><br>';
  16. span += '<span style="font-size: 16px">Lower</span>';
  17. span += '</span>';
  18.  
  19. $("#addText").append(span);
  20. span = $('#pieChartInfoText');
  21. span.css('left', textX + (span.width() * -0.5));
  22. span.css('top', textY + (span.height() * -0.5));
  23.  
  24. <div id="container" style="height: 400px; width: 500px"></div>​
Advertisement
Add Comment
Please, Sign In to add comment