我使用D3.js繪製svg行。我想通過在添加到行路徑之前移除重複(x,y)點來提高性能。在D3或javascript中完成此操作的最佳方法是什麼?我正在從json文件加載數據,用於此測試,但它可能會在服務器中的數組中出現。d3行過濾掉(刪除)複製點
請參閱下面的代碼片段和控制檯輸出。
感謝所有幫助
var x = d3.scale.linear().domain([xMin, xMax]).rangeRound([0, width]);
var y = d3.scale.linear().domain([yMin, yMax]).rangeRound([height, 0]);
var line = d3.svg.line()
.x(function(d, i) {
var xPoint = x((i + 1) * xMult);
console.log("xPoint= " + xPoint.toString());
return xPoint; })
.y(function(d) {
var yPoint = y(d);
console.log("yPoint= " + yPoint.toString());
return yPoint; })
.interpolate("basis-open")
.tension(0);
...
// Add the valueline path.
g.append("path")
.attr("class", "line")
.attr("d", line(data));
--------------------------------------------------
Console Output from two lines in code above
console.log("xPoint= " + xPoint.toString());
console.log("yPoint= " + yPoint.toString());
----------------------------------------------
xPoint= 0
yPoint= 24
xPoint= 0
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 1
yPoint= 24
xPoint= 2
yPoint= 24
xPoint= 2
yPoint= 25
xPoint= 2
yPoint= 25
xPoint= 2
yPoint= 24
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 3
yPoint= 25
xPoint= 4
yPoint= 25
感謝您的幫助,我將與數據的一些玩。但是,我真的正在尋找更多以D3.js爲中心的方法。問題是實際的線點來自比例數據d3.scale。而不是來自實際的數據。 – 2013-03-08 22:12:42