我使用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