简体   繁体   English

所有数据都在enter()占位符(D3)中

[英]All data is in enter() placeholder (D3)

I've got an update function with this code: 我有此代码的更新功能:

// actualy fetched from server. array of JS objects that I parsed to right type
var xData = [{
    id: 234234 // parsed as integer
    date: 15/11/2001 // parsed as date
    price: 6512 // parsed as integer
}];

// triggred by the user
function updateSVG() {

 // fetch new data from ther server
 xData = [];
 xData = [{
    id: 234234 // parsed as integer
    data: 15/11/2001 // parsed as date
    price: 6512 // parsed as integer
}];

 // join data
 var x = svg.selectAll(".x-class")
     .data(xData, function(d) { return d.id; });

 // new data
 x.enter().append("image")
     .attr('class', 'x-class')
     .attr("xlink:href", "x-image.png")
     .attr("width", 16)
     .attr("height", 19)
     .attr('y', 0);

 // current and new data
 x.transition()
     .attr("x", function(d) { return x(d.date); })
     .attr("y", function(d) { return y(d.date); });

 /// old data
 x.exit().remove();

}

What I expect is when I run this function the second or third time, most of the data will be UPDATE (ie not in enter), and just a few of the data will be in enter() and exit(). 我所期望的是,当我第二次或第三次运行此函数时,大多数数据将是UPDATE(即不在enter中),只有少数数据将在enter()和exit()中。

But all my data is in enter(). 但是我所有的数据都在enter()中。 No matter what. 无论。 The d.id is unique for sure. d.id肯定是唯一的。 Everything works well as expected but this issue. 一切都按预期工作,但此问题。 When I inspect the x object before and after I fetche the new data, all my data is in the enter() placeholder. 当我在获取新数据之前和之后检查x对象时,我所有的数据都在enter()占位符中。

Any ideas? 有任何想法吗? What am I missing? 我想念什么?

Code problems (Let us know if any of these help): 代码问题(让我们知道是否有任何帮助):

  1. What is x in the case of x(d.date) ? 什么是x在的情况下, x(d.date) Do you mean xData here? 你是说xData吗?

    x.attr("x", function(d) { return x(d.date); })

  2. What is this doing? 这是在做什么 You haven't defined data , or y . 您尚未定义datay (or arrayObjectIndexOf and yOffset but I suspect those are as implied) (或arrayObjectIndexOfyOffset但我怀疑它们是隐含的)

    return y(data[arrayObjectIndexOf(data, d.date, 'date')].price) - yOffset;

Also, since D3 is a data manipulation library, it's usually more difficult to help when we don't know what your data looks like. 另外,由于D3是数据处理库,因此当我们不知道您的数据是什么样时,通常很难提供帮助。 Sometimes we get an idea ( d.date ) but it could be important here (since you're apparently finding a price elsewhere instead of doing d.price ) 有时我们有个主意( d.date ),但在这里可能很重要(因为您显然是在别处寻找价格,而不是d.price

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM