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


Related Query

More Query from same tag