score:3
Accepted answer
What SVG element is focus? I think it must be a g
to work with multiple text
elements.
For the formatting, d3 has a neat function:
var format = d3.time.format('%H:%M');
// ...
focus.select('text').text(function(d) {return format(d.time);});
Edit: Working jsfiddle demo, showing two texts elements inside a group: jsfiddle.net/PRvGC/
score:1
I had a similar issue recently when I wanted to create 4 rectangles with different properties. I solved this with HTML ids and selectAll. Here is an example:
var van = road.selectAll('#van').data([5]).enter()
.append('rect')
.attr('x', function(d) { return 300})
.attr('y', function(d) { return 100})
.attr('width', 30)
.attr('height', 15)
.style('fill', 'brown');
Time formatting in D3: https://github.com/mbostock/d3/wiki/Time-Formatting
Source: stackoverflow.com
Related Query
- Append multiple 'text' elements in d3
- How to append multiple child elements to a div in d3.js?
- Get text of multiple DOM elements to reuse later in D3.js
- d3 drag multiple text elements inside a group SVG
- Issue adding multiple text elements to svg elements
- D3 - v5 update pattern on multiple text elements
- d3 js - trouble updating text elements in multiple line chart
- Appending multiple non-nested elements for each data member with D3.js
- D3: update data with multiple elements in a group
- Appending multiple svg text with d3
- How to change text elements in d3?
- How to append text to a div in D3
- How to avoid the overlapping of text elements on the TreeMap when child elements are opened in D3.js?
- How to append text to a line in d3.js
- D3 (v4): update pattern multiple elements in group
- How to append a text element with inline tspan children?
- Add single parent node by selecting multiple elements in D3
- Trying to append a click function to the node text in d3
- d3 - Append elements to external SVG file
- In D3, how can I create multiple elements for each data element based on value in data?
- How to append text in d3 force layout?
- How to append multiple rectangles in D3?
- d3.js / svg - how to dynamically append text to my arcs
- generate clipPaths for multiple elements in d3.js
- Get mean of all elements at a given index across multiple arrays
- Append svg icon always right behind the text
- Is it possible to append text to a text element in SVG?
- Appending multiple elements in D3
- D3.js: how to append elements when data is already bound?
- text elements not visible when appended from function
More Query from same tag
- D3.js: Circular clipping path isn't working?
- Access parsed csv file in browser's console
- How to nest my data by name on d3?
- Why d3 updates entire data
- Bar-chart Bars Bunching up with use of Brush
- Adding SVG elements on click of other elements
- How can I continue displaying a tooltip when it hovers over text in a d3 map
- D3 Dashboard chart not working properly
- Force re-render D3 component on React after state change in parent
- Javascript D3.js Manipulating arrays of objects
- Issue with displaying Chartjs annotation elements in Nextjs
- CSS: Centering text under a d3 slider on browser resize
- Issues with Datamaps D3 Pin/marker constant size and relative position while zooming
- TypeError: data.slice is not a function Loading csv d3 issue
- Starting d3 force-layout collapsed, text labels duplicating
- Save selected D3.js Treemap nodes to local file
- Why is the vertical scrollbar always visible
- display rectangles based on values
- Comparison of D3 and Dojo GFX
- Color scale domain not displaying correctly
- How to have the same scale in both x and y
- How to define the color of strokes
- Offline report with D3, md and equations
- D3 stacked cylinder chart to full height
- Organization chart - tree, online, dynamic, collapsible, pictures - in D3
- topojson.mesh outputting incorect path? (stroke-dasharray)
- d3 pie: redraw label on path change
- How to correctly access the transform of an SVG element during d3.transition
- How to customize d3plus large tooltip
- d3 async await fetch.json is not a function