-3
http://bl.ocks.org/cloudshapes/5661984
の下にオーバー行くと、私は大変な時間二つ
なぜthis
はd3.mouseで(この)SVGでの理解を持っています?私はthis
を理解していると思っていましたが、ここではthis
の定義でどのように派生するのか理解できません。
また、再描画中に、ここには何がありますか?ウォッチャーをd
に置くことができません。
// Redraw the path:
path
.attr("d", function(d) { return line(d);})
私はそれが現在のポイントであると仮定し、私は助けてください、この時点
でこのd
を理解していません。どうもありがとうございます。
var margin = {top: 10, right: 10, bottom: 20, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var npoints = 100;
var ptdata = [];
var line = d3.svg.line()
.interpolate("basis")
.x(function(d, i) { return d[0]; })
.y(function(d, i) { return d[1]; });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var svgagain = d3.select("body").select("svg")
.on("mousemove", function() { var pt = d3.mouse(this); tick(pt); });
var path = svg.append("g")
.append("path")
.data([ptdata])
.attr("class", "line")
.attr("d", line);
function tick(pt) {
// push a new data point onto the back
ptdata.push(pt);
// Redraw the path:
path
.attr("d", function(d) { return line(d);})
// If more than 100 points, drop the old data pt off the front
if (ptdata.length > npoints) {
ptdata.shift();
}
}
の提案に基づいてドキュメントを読んだ後、私の質問への回答は、SVGラインが2つのアプローチを使用して作成することができ
The specified listener is invoked in the same manner as other operator functions, being passed the current datum d and index i, with the this context as the current DOM element.
d属性を使用してsvgパスを作成しました。 https://developer.mozilla.org/en-US/docs/Web/SVG/Element/path –
okですが、関数の目盛りはここで 'd'の定義をどうやって取得しますか? – user3502374
D3の豊富なドキュメントについてご存知ですか? ['selection.on()'](https://github.com/d3/d3-3.x-api-reference/blob/master/Selections.md#on)のセクションの1つの文は、あなたの質問:* "指定されたリスナは、このコンテキストを現在のDOM要素として現在のデータムdとインデックスiを渡している他の演算子関数と同じ方法で呼び出されます。" * – altocumulus