gython
gython

Reputation: 875

Understanding code and key keywords in Javascript

I am following this d3.js example.

However I am struggling to understand this line:

.defer(d3.csv, "https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world_population.csv", function(d) { data.set(d.code, +d.pop); })

What are d.code and d.pop doing here?

What are code and pop standing for exactly?

Upvotes: 1

Views: 83

Answers (2)

innocent
innocent

Reputation: 965

If you open the link

https://raw.githubusercontent.com/holtzy/D3-graph-gallery/master/DATA/world_population.csv

you can see it's a CSV file consisting of the country its area code and the population on the map for the area. In short its

d.code -> Area code of the country

d.pop -> Population of the country which is getting used for creating the choropleth map

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074355

If you look at that file you'll see that it is a CSV with three columns: name, code, and pop:

name,code,pop
Antigua and Barbuda,ATG,83039
Algeria,DZA,32854159
Azerbaijan,AZE,8352021
Albania,ALB,3153731
...

D3 is reading the file and, for each row, creating an object with properties named based on the header row in the file and passing that object to the callback. The callback is converting d.pop from string to number and calling data.set to put the data in the document.

Upvotes: 2

Related Questions