Skip to content Skip to sidebar Skip to footer

Create Dynamic Vertical Rule In D3

I want to create a vertical rule like the one shown at http://bost.ocks.org/mike/cubism/intro/demo-stocks.html that updates its value dynamically according to the user's mouse. Thi

Solution 1:

You need to update your question to include more detail about what you actually want, but here's one implementation using d3: http://jsfiddle.net/q3P4v/

d3.select('html').on('mousemove', function() {
    var xpos = d3.event.pageX;
    var rule = d3.select('body').selectAll('div.rule')
        .data([0]);
    rule.enter().append('div')
        .attr('class', 'rule')
      .append('span');
    rule.style('left', xpos + 'px');
    rule.select('span').text(xpos);
});

Note that this depends on some associated CSS, as shown in the fiddle.

Post a Comment for "Create Dynamic Vertical Rule In D3"