Heat Map Data Visualisation D3
How do I make an heat map data visualisation d3?
Heat map made in d3 comparing global land temperatures since 1753. Made for fcc data visualisation course. What is a heat map data visualisation d3? How do you make a heat map data visualisation d3? This script and codes were developed by Adam on 28 November 2022, Monday.
Heat Map Data Visualisation D3 - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Heat Map Data Visualisation D3</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container"> <h1>Monthly Global Land-Surface Temperature</h1> <h2>1753 - 2015</h2> <p>Temperatures are in Celsius and reported as anomalies relative to the Jan 1951-Dec 1980 average.</p> <p>Estimated Jan 1951-Dec 1980 absolute temperature ℃: 8.66 +/- 0.07</p> <svg class="chart"></svg> <div class="range"> <div class="temp">0℃</div> <div class="legend"></div> <div class="temp">+11℃</div> </div>
</div> <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Heat Map Data Visualisation D3 - Script Codes CSS Codes
body { height: 100%; text-align: center; background: linear-gradient(#480048, #00c6ff); color: #fff; font-family: 'verdana', sans-serif; font-size: 20px;
}
h1 { margin: 0.5em 0 0; font-size: 2em; font-weight: 700;
}
h2 { font-size: 1.5em; font-weight: 700; margin-bottom: 0.3em;
}
p { font-size: 0.6em;
}
.chart text { fill: #fff; font: 20px 'verdana';
}
.axis path { stroke: #fff;
}
.chart .mouseover { fill: #000 !important;
}
.tooltip { position: absolute; opacity: 0; padding: 0.5em; color: #480048; background-color: #fff; border-radius: 0.2em; text-align: left;
}
.range { width: 400px; margin: 20px auto; display: flex; justify-content: center;
}
.legend { width: 300px; height: 30px; background: linear-gradient(90deg, #add8e6, #9da7ef, #8477f5, #5b43fb, #4a1af6, #a860ca, #d59d9b, #f3da5e, #fff600, #ffde00, #ffc700, #ffaf00, #ff9500, #ff7800, #ff5600, #ff1f00, #c51708, #811b0c, #421509, #000000);
}
Heat Map Data Visualisation D3 - Script Codes JS Codes
"use strict";
var url = 'https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/global-temperature.json';
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var colors = ['#add8e6', '#9da7ef', '#8477f5', '#5b43fb', '#4a1af6', '#a860ca', '#d59d9b', '#f3da5e', '#fff600', '#ffde00', '#ffc700', '#ffaf00', '#ff9500', '#ff7800', '#ff5600', '#ff1f00', '#c51708', '#811b0c', '#421509', '#000000'];
d3.json(url, function (d) { var height = 500; var width = 800; var padding = 50; var baseTemp = d.baseTemperature; var data = d.monthlyVariance; var lowTemp = d3.min(data, function (d) { return baseTemp - d.variance; }); var highTemp = d3.max(data, function (d) { return baseTemp - d.variance; }); //create tooltip element var tooltip = d3.select(".container").append("div").attr("class", "tooltip"); var colorScale = d3.scaleQuantile().domain([lowTemp, 12]).range(colors); var chart = d3.select(".chart").attr('height', height + padding * 2).attr('width', width + 300).append('g').attr("transform", "translate(" + 150 + "," + padding + ")"); var x = d3.scaleLinear().range([0, width]).domain(d3.extent(data, function (d) { return d.year; })); var y = d3.scaleLinear().range([0, height]).domain(d3.extent(data, function (d) { return d.month; })); // create axis var xAxis = d3.axisBottom().scale(x).ticks(10).tickFormat(d3.format(".4")); var yAxis = d3.axisLeft().scale(y).ticks(0); var yLabel = chart.selectAll(".yLabel").data(months).enter().append("text").text(function (d) { return d; }).attr("x", 0).attr("y", function (d, i) { return i * (height / 11); }).style("text-anchor", "end").attr("transform", "translate(-10," + 10 + ")").attr("class", "yLabel"); //Create group and append and style axis chart.append("g").attr("class", "x axis").attr("transform", "translate(0," + 525 + ")").call(xAxis); chart.append("g").attr("class", "y axis").call(yAxis); chart.selectAll("rect").data(data).enter().append("rect").attr("class", "bar").attr("x", function (data) { return x(data.year); }).attr("y", function (data) { return y(data.month); }).attr("width", 3).attr("height", height / 12).attr("transform", "translate(0, -20)").style("fill", function (d) { return colorScale(baseTemp + d.variance); }) //Show tooltip on mouseover .on("mouseover", function (data) { d3.select(undefined).attr("class", "mouseover"); var format = d3.format('.4'); //append data into tooltip and style tooltip.style("opacity", 0.8).html("<span>" + months[data.month - 1] + " " + data.year + "</span><br><span>Temp: " + ("" + format(data.variance + baseTemp)) + "℃</span>").style("left", d3.event.pageX + 10 + "px").style("top", d3.event.pageY - 60 + "px"); }).on("mouseout", function () { d3.select(this).attr("class", "null"); });
});
Developer | Adam |
Username | rzencoder |
Uploaded | November 28, 2022 |
Rating | 3 |
Size | 5,591 Kb |
Views | 6,072 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Whack-a-Mole and Simon Game | 10,604 Kb |
React Leaderboard | 4,333 Kb |
Placeholder Portfolio | 7,180 Kb |
Scrolling Effects Practice | 6,441 Kb |
React Game of Life | 7,264 Kb |
Random Movie Quote Generator | 3,861 Kb |
Markdown Previewer | 3,929 Kb |
Scatterplot Graph D3 | 5,762 Kb |
CSS World Flags | 8,782 Kb |
Countdown Anagram Game | 7,625 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Ionic Infinite outside ion-content with ion-pane | Felquis | 3,117 Kb |
Placeholder support for contentEditable elements, without JavaScript | Flesler | 1,863 Kb |
Lecture 1 | Law | 0 Kb |
CSS eye follow | Pedrocampos | 2,592 Kb |
Sticky menu on scroll | Senff | 2,869 Kb |
CSS3 Fullscreen Background Slideshow | Leetech | 3,435 Kb |
Twinner Spinner II | Katydecorah | 2,974 Kb |
Fun animations with CSS3 | Minimalmonkey | 2,360 Kb |
Toggle Time | Petebot | 5,345 Kb |
Bootstrap Carousel Fade Transition | Rowno | 2,484 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!