Hi Daniel. Your last line there, .attr('id','key.id')
, will set the id attribute of every circle element to be the same thing, the literal string âkey.idâ. For it to be dynamic (different for every circle, based on an id property in the bound data object), youâd have to pass a function as the second argument of attr, like:
.attr("id", function(d) { return d.id; })
or, equivalently:
.attr("id", (d) => d.id)
The next question is, whatâs âdâ there? In your case I think itâd be one of the elements of the âvaluesâ array. I canât see what those objects are like, though it looks like they at least have âdateâ and âmeasurementâ properties. If those objects have the âidâ youâd want to use, I think you should be all set.
But if the id you want to use is up in that parent array (TemperatureExterieure, TemperatureBallon, Humidite, etc.), you wonât have access to it in that âdâ object, and D3 doesnât pass it in. (This common issue is discussed here.) So you have a few options:
1 â Access the bound data of the parent. It looks like your circles are appended to a selection called âlinesâ (which may be <G>
elements?); I think the id should be attached to the elements of that selection:
.attr("id", function(d) {
return d3.select(this.parentNode).datum().id;
})
2 â Rewrite the code to keep a reference to the parentâs data. For example:
lines.each(function(parentData) {
d3.select(this)
.selectAll("circle")
.data(parentData.values)
.enter()
.append("circle")
.attr("id", parentData.id)
})
3 â Transform the data to be more âtidyâ, so each element of values also has the id:
data = data.map(({id, values}) => ({id, values: values.map(d => ({...d, id}))}))
Let me know if that works. If you post an example notebook, we may be able to give more specific advice.