最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to center title over SVG chart with d3.js? - Stack Overflow

programmeradmin2浏览0评论

DEMO: /

I've created a simple SVG with two axes and appended a text element to serve as the title of the chart. But I can't find a reliable way to center the title over the midpoint of the chart. I'd like the middle of the text element to be aligned over the '0.5' tick on the x-axis. To me, visually, that's the middle of the chart.

I'd like a solution that is generic, meaning it doesn't matter how long the text string is, the middle will always be over '0.5'. It also shouldn't matter what type of axis the x-axis is (whether it's linear, ordinal, etc.)

DEMO: http://jsfiddle/29j6ozqn/

I've created a simple SVG with two axes and appended a text element to serve as the title of the chart. But I can't find a reliable way to center the title over the midpoint of the chart. I'd like the middle of the text element to be aligned over the '0.5' tick on the x-axis. To me, visually, that's the middle of the chart.

I'd like a solution that is generic, meaning it doesn't matter how long the text string is, the middle will always be over '0.5'. It also shouldn't matter what type of axis the x-axis is (whether it's linear, ordinal, etc.)

Share Improve this question asked Oct 30, 2014 at 0:28 jlewkovichjlewkovich 2,7752 gold badges36 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Use text-anchor: middle or text-align: center instead of text-anchor: start: Fiddle.

发布评论

评论列表(0)

  1. 暂无评论