Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning D3.js Mapping
  • Table Of Contents Toc
  • Feedback & Rating feedback
Learning D3.js Mapping

Learning D3.js Mapping

By : Newton, Oscar Villarreal
4.3 (7)
close
close
Learning D3.js Mapping

Learning D3.js Mapping

4.3 (7)
By: Newton, Oscar Villarreal

Overview of this book

If you are interested in creating maps for the web GIS data, this book is for you. Familiarity with D3.js will be helpful but is not necessary.
Table of Contents (9 chapters)
close
close
6
6. Finding and Working with Geographic Data
8
Index

Experiment 2 – creating choropleths


One of the most common uses of D3.js maps is to make choropleths. This visualization gives you the ability to discern between regions, giving them a different color. Normally, this color is associated with some other value, for instance, levels of influenza or a company's sales. Choropleths are very easy to make in D3.js. In this experiment, we will create a quick choropleth based on the index value of the state in the array of all the states. Look at the following code or open up your browser to http://localhost:8080/chapter-4/example-3.html.

We will only need to modify two lines of code in the update section of our D3 code. Right after the enter section, add the following two lines:

  //Update
  var color = d3.scale.linear().domain([0,33]).range(['red', 'yellow']);
  mexico.attr('fill', function(d,i) {return color(i)});

The color variable uses another valuable D3 function named scale. Scales are extremely powerful when creating visualizations in D3; much...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech

Create a Note

Modal Close icon
You need to login to use this feature.
notes
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Delete Note

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Edit Note

Modal Close icon
Write a note (max 255 characters)
Cancel
Update Note

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY