I've been working on a d3.js time series line chart.
I am using d3.nest
and then looping through the nested groups to create each line.
The complete code Here
What I would like to do is have each line's label (the country name) show up on the y-axis at the position of the last observation (given by credit
). To find this position I use:
dataNest.forEach(function(d) {
var position = d.values[6].credit;
console.log("Selected Value", position);
Then later pass position
to .attr("y", y(position))
when I append the text.
The issue I'm having is that the position returned from d.values[6].credit
is correct as logged in the console. But I get an
Uncaught TypeError: Cannot read property 'credit' of undefined
error. This leads to the axes not being plotted.
(Eventually I want the labels to appear on mouseover
, but that is for another day).
Slovak Republic only has 2 data points:
Slovak Republic,SK,Jan 2007,100
Slovak Republic,SK,Jan 2008,105.2
Instead of the hard-coded 6, just use:
var position = d.values[d.values.length-1].credit;
Example here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.