score:0
youll need to create a 'g' tag then append both the circle and the text to that 'g' as you cant append text directly to an svg shape so something like this (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 you want here');
CSS
.text{
text-anchor: middle;
color: steelblue;
position:relative;
font: 14px Calibri;
}
Something along those lines :)
Source: stackoverflow.com
Related Query
- how to create circles with text over svg file using d3 js?
- How to create SVG with grid lines using D3JS
- how to combine angularjs dynamic text input with d3js-created svg circles for filtering
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- How to show a tooltip with value when mouseover a svg line graph using d3.js?
- How to add filled sections to SVG circles using d3.js
- How do I create a minimap of an SVG using D3 v5 and show the current viewport dimensions?
- How do I save an svg node to a file using nodejs?
- How to center title over SVG chart with d3.js?
- How to create a flow layout in SVG using D3.js?
- How do I create a multiline chart using d3js with json formatted for nvd3?
- How to add links from CSV file to SVG elements generated with D3?
- How to create responsive svg using d3.js
- How to create a % difference arrow line with value in a bar chart using D3.js
- Using D3 to generate SVG Pie Chart how to vertically align text
- Match SVG text element id with data id using D3
- How to iterate over data in JSON file using D3 javascript
- How so create complex SVG shapes using D3JS?
- d3js v5: Create a SVG with groups from a JSON file
- Drawing multiple circles with text in them using d3.js
- How do I append the text tag to just one svg e.g. svg tag with "id=50"?
- With D3, how can I avoid SVG graph links being rendered over nodes?
- How to redraw the svg filled with circles in D3?
- D3JS: help to create a SVG text element inside a circle using D3js
- Create rect with blurred stroke in svg using d3.js
- How to make an svg text with d3.js that flashes from black to white an back continuously?
- How do I do a line break with SVG text element ?
- Button with text label: How do I keep the hover color even when over text label?
- How to dynamically create append svg line using d3js?
- How to create a heatmap with numbers using Leaflet map?
More Query from same tag
- Add a border to the slices of a pieChart in dc.js + labelColors
- d3.tsv Find Maximum Value
- Handling D3v3 Labels Overlapping
- Calling D3 Tooltip in context of data visualization in AngularJS
- Hide all text on y axis dc.js bar chart
- CORS issue on noe4j with D3.js
- Tooltip on invisible SVG element
- Origin null is not allowed by Access-Control-Allow-Origin.
- How to turn Reingold–Tilford Tree into double sided tree in D3
- Draw the progress path from right to left in semi circle donut chart using d3js
- Implementing d3-2way-tree for multilevel tree
- Jumping behavior when dragging groups of elements using d3.drag
- How to update a d3 grouped barchart with new data by using join in v6
- d3 treemap from array without hierarchy
- d3 mercator, geo, and path methods
- D3.js Focus + Context Overflow
- dimple - color by series in bubble chart
- How can I run d3-cloud in node.js
- d3.js bar charts transitioning between multiple csv files
- Parent css transform affecting d3.mouse points
- How to share parsed D3.js CSV between functions - scoping issue?
- Add a selection box for NVD3 chart
- D3.js Circles on Map
- d3.js translate header text above or below a circle based on array index
- Add labels to a d3 bar chart
- Is there any way that I can covert bar to circle in D3 JS
- Manipulate d3.js pack layout with HTML5 Range Input
- What is the default representation of date in d3.js?
- How to export complete SVG into PNG as my SVG is very large.
- Why don't translate(${x},${y}) and translate(${-x},${-y}) cancel out?