Reputation: 397
I'm trying to create a tooltip like this one: http://bl.ocks.org/sdbernard/2e44bd82c9d048b88451/2b31b98b8f6acb8d7c6026b5eec801e2f1f61ab2
The underlying code and data structure of that block is similar to that of my own, except that I'm also doing small multiples. Here's my Plunker: http://plnkr.co/edit/BsLMhbldIYvZEVOu23aM?p=preview
When I try to adapt the block's tooltip to my visualization, using month and year — or even just the year (as in the original) — I get the error message: "Cannot read property '-1' of undefined"
The problematic code seems to be here:
var mousex = d3.mouse(this);
mousex = mousex[0] + 10;
var invertedx = xScale.invert(mousex);
// This doesn't work: //
invertedx = invertedx.dates;
var selected = (d.value);
mousedate = dates.indexOf(String(invertedx));
pro = d.value[mousedate].y;
This also doesn't work:
invertedx = invertedx.getMonth() + invertedx.getFullYear();
var selected = (d.value);
for (var k = 0; k < selected.length; k++) {
dates[k] = selected[k].x
dates[k] = dates[k].getMonth() + dates[k].getFullYear();
}
mousedate = dates.indexOf(invertedx);
pro = d.value[mousedate].y;
Here's my Plunker: http://plnkr.co/edit/BsLMhbldIYvZEVOu23aM?p=preview I've spent almost a week on this, without much or any progress. In advance, thanks very much for your help.
Upvotes: 0
Views: 347
Reputation: 179
What I've been able to find so far is if you do console.log(d) right before the problem area, you don't have a d.value defined. What I'm seeing instead is d.values, which is an array.
Also mousedate ends up as -1 because there isn't an index in dates that it's looking for.
I probably haven't found the whole solution, but fixing that should help get you back on track a bit, at least.
Upvotes: 1