Welcome to d3aday! If this is your first time, we recommend reading the about page before jumping in.
The Inspiration
For this exercise, we’ll be creating a crowd favorite data visualization type - the heatmap. The inspiration comes from this example on Stack Overflow, created with Seaborn:
The Exercise
We’ll re-use the historical monthly Raleigh temperature data compiled for a previous exercise, available here. In this case, we don’t necessarily want all the years, so we can filter it down and select, say, one year per decade. We’ll stick with the inspiration’s scales and put the months in the Y axis and years in the X axis. Each square will represent the average temperature for a specific month.
This is mostly a straightforward apply-scales-to-data exercise. However, the data itself can pose a subtle datetime issue to work through. If you’re in the US, you will likely need to use UTC versions of datetime methods, or else the months will be off by 1. The time for each date is midnight on the first day of each month, in UTC, and using standard methods generates local datetimes, which in my time zone is 4-5 hours earlier than midnight, on the previous month. For example, to filter the data to only one year per decade, you can use this function (note the UTC-flavored method):
A Solution
My result looks like so:
My final JavaScript code is below, but I encourage you to try it yourself.
Complete code and a working example are available on codepen.