0

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.

This demo uses cubism.js but I'd like to use d3 and/or jQuery to achieve the same effect. Any suggestions?

EDIT: I've tried creating rules according to the ones in this thread (How to make a vertical line in HTML), but I don't know how to position it and move it according to the user's mouse position.

4

1 回答 1

3

您需要更新您的问题以包含有关您实际想要的更多详细信息,但这是使用 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);
});

请注意,这取决于一些相关的 CSS,如小提琴所示。

于 2013-04-24T23:12:01.227 回答