Chackers
Chackers

Reputation: 25

Only one defined value returned by d3.csv

When reading in a csv file in d3.js, only the first column reads in correctly. How do I get the other columns to return defined values?

I have tried converting the variables; e.g:

d.value=+d.value;

I have also searched and tried to match my lines of code to previous examples. The only difference I found is that other code examples had functions that accessed some of the variables more than once (i.e. there was a previous reference of the data in the code).

var data = d3.select(this).data()[0];

var htmlData = [
    data.id, 
    data.pd
];

div.html(htmlData.join("<br>"))
    .style('left', (d3.event.pageX + 94) + 'px')
    .style('top', (d3.event.pageY - 32) + 'px');        
}

My code, forked from mbostock's block Radial Cluster Dendrogram: https://blockbuilder.org/MyAkosombo/666f1d3791b90a5111d57cfa3b93c10b

Expectations: I expect a tooltip that has the id and value shown when you hover over the name of the id.

Upvotes: 2

Views: 39

Answers (1)

Gerardo Furtado
Gerardo Furtado

Reputation: 102198

The value property is inside the property named data. This is the default outcome of the tree generator.

Therefore, it should be:

var htmlData = [
    data.id, 
    data.data.value
];

Here is your updated blockbuilder: https://blockbuilder.org/GerardoFurtado/0ba57a020d16b5b582605e9779697417

Upvotes: 1

Related Questions