admin管理员组文章数量:1432620
how can i add a tooltip to each bar in a barchart generated using svg path... Is it possible to use bootstrap tooltip...? I have provided my svg path below
<path class="foreground bar" clip-path="url(#clip 0)" d="M36,100V68h20V100M108,100V29h20V100M180,100V71h20V100M252,100V-4h20V100M324,100V87h20V100"/>
I have provided the svg generated barchart in below fiddle / ... How can i add tooltip to each bar ??
Any suggestions would be appreciated.
how can i add a tooltip to each bar in a barchart generated using svg path... Is it possible to use bootstrap tooltip...? I have provided my svg path below
<path class="foreground bar" clip-path="url(#clip 0)" d="M36,100V68h20V100M108,100V29h20V100M180,100V71h20V100M252,100V-4h20V100M324,100V87h20V100"/>
I have provided the svg generated barchart in below fiddle http://jsfiddle/mfAc4/6/ ... How can i add tooltip to each bar ??
Any suggestions would be appreciated.
Share Improve this question edited Nov 2, 2012 at 13:42 selvagsz asked Nov 2, 2012 at 12:46 selvagszselvagsz 3,8721 gold badge26 silver badges34 bronze badges2 Answers
Reset to default 2Not sure what you mean by bootstrap, but most UAs will turn a title element child into a tooltip. E.g.
<path class="foreground bar" clip-path="url(#clip 0)" d="M36,100V68h20V100M108,100V29h20V100M180,100V71h20V100M252,100V-4h20V100M324,100V87h20V100">
<title>tooltip text</title>
</path>
Have a look at: http://bl.ocks/2973775
Note in your jsFiddle you are not actually using d3. But you can easily add it to get a tooltip see here:
var svg = d3.select("svg").attr("width", 400).attr("height", 400);
var vis = svg.append('g');
var txt = vis.append('text')
.attr({ transform: 'translate(5,20)', fill:'red'})
.text("Node Info");
d3.selectAll('.bar')
.on("mouseover", function(d) {
var mousePos = d3.mouse(this);
txt.text(mousePos);
txt.attr({transform: 'translate(' + mousePos + ')'});
})
.on("mousemove", function(d) {
var mousePos = d3.mouse(this);
txt.attr({transform: 'translate(' + mousePos + ')'});
});
To figure out which bar you will have to look at the mouse x position. You should consider using a d3 scale for this (it will map in both directions - check out the invert function).
本文标签: javascriptAdding tooltip to bar chart generated using svg pathStack Overflow
版权声明:本文标题:javascript - Adding tooltip to bar chart generated using svg path - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745588222a2665039.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论