javascript - how to create circles with text over svg file using d3 js? -


i beginner d3 js. have div contains object tag having svg file.
i need create circle texts on svg file , bind click functions on them using d3 js.
thanx in advance. below html code:

<div class="span8 canvasdiv">     <object data="img/floor.svg" type="image/svg+xml" id="floorcanvas"></object> </div> 

js code:

var svgcontainer = d3.select("#floorcanvas"); var circle = svgcontainer.append("circle")                          .attr("cx", 30)                          .attr("cy", 30)                          .attr("r", 20); 

youll need create 'g' tag append both circle , text 'g' cant append text directly svg shape (not tested) :

html :

 <div class="span8 canvasdiv">         <object data="img/floor.svg" type="image/svg+xml" id="floorcanvas"></object>         </div> 

js code:-

 var svgcontainer = d3.select("#floorcanvas").append('svg').append('g').attr('id', 'circlewithtext');  var circlewithtext = d3.select("#circlewithtext");   circlewithtext .append("circle")                 .attr("cx", 30)                 .attr("cy", 30)                 .attr("r", 20);   circlewithtext.append('text')                 .attr('class', 'text')                 .attr("dx", "0")                 .attr("dy", "0")                 .text('what ever want here'); 

css

.text{     text-anchor: middle;     color: steelblue;     position:relative;     font: 14px calibri; } 

something along lines :)


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -