I'm stumped by what I'd hoped would be a minor tweak to Mike Bostock's unemployment choropleth ( https://bl.ocks.org/mbostock/4060606 ): adding the county names and state abbreviations to the .tsv file.
I created a new unemployment2.tsv by merging Bostock's original with a list of county ID codes, names and states from the Census bureau. A sample:
id rate state county
01001 5.1 AL Autauga County
01003 4.9 AL Baldwin County
...
56043 4.5 WY Washakie County
56045 4.9 WY Weston County
In the javascript, I modified the d3.queue() block as follows, in an attempt to access the state and county columns:
d3.queue()
.defer(d3.json, "https://d3js.org/us-10m.v1.json")
.defer(d3.tsv, "unemployment2.tsv", function(d) {
unemployment.set(d.id, +d.rate, d.county, d.state);
county = d.county;
state = d.state;
})
.await(ready);
I then modified the tooltip line of the svg.append block as follows:
.text(function(d) { return d.id + " - " + county + ", " + state + " - " + d.rate + "%"; });
The resulting map does access the new columns in the .tsv file, but the tooltip displays the county and state only from the last line (Weston County, WY) no matter which county you mouse over. (Oddly, the id and rate fields do reflect the correct county in the tooltip.)
I’m seeing the same behavior on my server as on Plunker ( https://plnkr.co/edit/vrm4FuBVEQc7lCSnbytl?p=preview ).
Appreciate any insights as to what I'm doing wrong/how to fix.
d.county
,d.state
(as you do with rate and id in the tooltip tip - column names set property names with d3.tsv/csv, logd
in the defer method to see).