d3.js - How do I parse a JSON file to bind data to a d3 choropleth map -


i'm trying take data in json file , link geojson file create choropleth map county colours bound "amount" value corresponding "comment" value bound div when mouseover county.

my code @ http://bl.ocks.org/eoiny/6244102 work generate choropleth map when counties.json data in form:

"carlow":3,"cavan":4,"clare":5,"cork":3, 

but things tricky when try use following form:

{ "id":"carlow", "amount":11, "comment":"the figures carlow show something." }, 

i can't head around how join "id": "carlow" counties.json , "id": "carlow" path created ireland.json, while @ same time have access other values in counties.json i.e. "amount" , "comment".

apologies inarticulate question if point me example or reference great.

i preprocess data when it's loaded make lookup easier in quantize function. basically, replace this: data = json; this:

data = json.reduce(function(result, county) {     result[county.id] = county;     return result; }, {}); 

and in quantize function, @ amounts this:

function quantize(d) {     return "q" + math.min(8, ~~(data[d.id].amount * 9 / 12)) + "-9"; } 

what preprocessing turn array (easily accessed index):

[{id: 'xyz', ...}, {id: 'pdq', ...}, ...] 

into object county keys (easily accessed county id):

{'xyz': {id: 'xyz', ...}, 'pdq': {id: 'pdq', ...}, ...} 

here's working gist: http://bl.ocks.org/rwaldin/6244803


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -