Visualize Data with a Heat Map
How do I make an visualize data with a heat map?
What is a visualize data with a heat map? How do you make a visualize data with a heat map? This script and codes were developed by Codoer on 07 December 2022, Wednesday.
Visualize Data with a Heat Map - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Visualize Data with a Heat Map</title> <link rel='stylesheet prefetch' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id='app'></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Visualize Data with a Heat Map - Script Codes CSS Codes
body { background: url(http://cdn.backgroundhost.com/backgrounds/subtlepatterns/egg_shell.png);
}
.heatmap { text-align: center; margin-top: 60px;
}
.tooltip1 { width: 210px; height: auto; padding: 5px; background-color: black; border-radius: 10px; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4); pointer-events: none; opacity: 0.8;
}
svg { background-color: white; opacity: 1; box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
}
.year,
.currentTemp,
.variance { color: white;
}
Visualize Data with a Heat Map - Script Codes JS Codes
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var HeatMap = function (_React$Component) { _inherits(HeatMap, _React$Component); function HeatMap() { _classCallCheck(this, HeatMap); return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); } HeatMap.prototype.componentDidMount = function componentDidMount() { $.getJSON('https://raw.githubusercontent.com/c0d0er/D3-Visualize-Data-with-a-Heat-Map/master/globeTemp.json', function (data) { var heatData = data.monthlyVariance; var baseTemp = data.baseTemperature; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var colors = ["#5e4fa2", "#3288bd", "#66c2a5", "#abdda4", "#e6f598", "#ffffbf", "#fee08b", "#fdae61", "#f46d43", "#d53e4f", "#9e0142"]; var margin = { top: 90, right: 80, bottom: 95, left: 80 }; var years = d3.extent(heatData, function (d) { return d.year; }); //[1753, 2015]; var temp = d3.extent(heatData, function (d) { return d.variance; }); //[-6.976, 5.228]; var w = 1200 - margin.right - margin.left; var h = 600 - margin.top - margin.bottom; var rectXwidth = w / (years[1] - years[0] + 1); var colorScale = d3.scaleQuantile().domain([temp[0] + baseTemp, temp[1] + baseTemp]).range(colors); var xScale = d3.scaleLinear().domain(years).range([0, w]); var yScale = d3.scaleTime().domain([new Date(2016, 0, 1), new Date(2016, 11, 31)]).range([0, h]); var div = d3.select('.heatmap').append('div'); var svg = d3.select('.heatmap').append('svg').attr('width', w + margin.right + margin.left).attr('height', h + margin.top + margin.bottom).append('g').attr("transform", "translate(" + margin.left + "," + margin.top + ")"); svg.selectAll('rect').data(heatData).enter().append('rect').attr('x', function (d) { return (d.year - years[0]) * rectXwidth; }).attr('y', function (d) { return (d.month - 1) * (h / 12); }).attr('width', rectXwidth).attr('height', h / 12).attr('fill', function (d) { return colorScale(d.variance + baseTemp); }).on('mouseover', function (d) { div.html('<div class="tooltip1"><span class="year">' + d.year + ' - ' + months[d.month - 1] + '</span><br><span class="currentTemp">temperature: ' + ((baseTemp + d.variance) * 1.8 + 32).toFixed(1) + ' ℉ / ' + (baseTemp + d.variance).toFixed(2) + ' ℃</span><br><span class="variance">variance: ' + (d.variance * 1.8 + 32).toFixed(1) + ' ℉ / ' + d.variance.toFixed(2) + ' ℃</span></div>').style('left', d3.event.clientX + 5 + 'px').style('top', d3.event.clientY - 50 + 'px').style('position', 'absolute'); }).on('mouseout', function () { d3.select('.tooltip1').classed('hidden', 'true'); }); svg.append('g') //add y axis .attr('class', 'y axis').attr('transform', 'translate(0,0)').style('font-size', '12px').call(d3.axisLeft(yScale).ticks(d3.timeMonth).tickSize(16, 0).tickFormat(d3.timeFormat("%B"))).selectAll("text") //change y axis text .attr("y", 20).attr("x", -5) //.attr("dy", ".35em") //.attr("transform", "rotate(90)") .style("text-anchor", "beginning"); svg.append('g') //add x axis; .attr('class', 'x axis').attr('transform', 'translate(0,' + h + ')').style('font-size', '12px').call(d3.axisBottom(xScale).ticks(19).tickFormat(d3.format("")) //or use format("y") or format("Y") ); //setup legend data; var legendArr = [0].concat(colorScale.quantiles()); console.log(legendArr); // setup legend; var legend = svg.selectAll('.legend').data(legendArr).enter().append('g').attr('class', 'legend'); //add colors of legend; legend.append('rect').attr('x', function (d, i) { return 40 * i + (w - 40 * colors.length); }).attr('y', h + 35).attr('width', 40).attr('height', 40).style('fill', function (d, i) { return colors[i]; }); //add text of legend; legend.append('text').text(function (d) { return (d * 1.8 + 32).toFixed(1); }) //.attr('x', (d, i) => 40 * i + (w - 40 * colors.length) + 5) //.attr('y', h + 77); .attr('x', function (d, i) { return 40 * i + (w - 40 * colors.length) + 5; }).attr('y', h + 50); legend.append('text').text(function (d) { return d.toFixed(2); }).attr('x', function (d, i) { return 40 * i + (w - 40 * colors.length) + 5; }).attr('y', h + 70); //add text for svg; svg.append('text').attr("transform", "translate(" + w / 2 + " ," + -45 + ")").style("text-anchor", "middle").attr('fill', 'black').style('font-size', '1.9em').text("1753-2015 Monthly Global Land-Surface Temperature"); svg.append('text').attr("transform", "translate(" + w / 2 + " ," + -20 + ")").style("text-anchor", "middle").attr('fill', 'black').style('font-size', '0.85em').text("Temperatures are in Fahrenheit/Celsius and reported as anomalies relative to the Jan 1951-Dec 1980 average. Estimated Jan 1951-Dec 1980 absolute temperature ℃: 8.66 +/- 0.07"); }); }; HeatMap.prototype.render = function render() { return React.createElement("div", { className: "heatmap" }); }; return HeatMap;
}(React.Component);
ReactDOM.render(React.createElement(HeatMap, null), document.getElementById('app'));
Developer | Codoer |
Username | c0d0er |
Uploaded | December 07, 2022 |
Rating | 3 |
Size | 6,445 Kb |
Views | 10,120 |
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 |
Visualize National Contiguity with a Force Directed Graph | 5,906 Kb |
Visualize US GDP Data with a Bar Chart | 7,811 Kb |
Jd wiki | 3,082 Kb |
Show the Local Weather | 2,904 Kb |
Perseverance Portfolio | 2,756 Kb |
React Camper Leaderboard | 5,258 Kb |
Game of Life React | 6,561 Kb |
Calculator | 3,530 Kb |
Visualize Meteorites Map Data Across the Globe | 5,842 Kb |
React Markdown Previewer | 3,190 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 |
Resume | Rottingroom | 5,483 Kb |
Animated Vertical CSS3 Menu Black | MaCeLMp4 | 2,750 Kb |
CSS Colors | Alexpate | 2,232 Kb |
SCSS Unit Conversion | Jakob-e | 8,210 Kb |
Perforated foil | 0x04 | 2,617 Kb |
React Markdown Previewer | C0d0er | 3,190 Kb |
A Pen by Matt Popovich | Mpopv | 3,349 Kb |
Import shader in three.js | Khangeldy | 2,636 Kb |
E-mail Template | SoloMDFK | 4,871 Kb |
Degree Picker | Idered | 4,307 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!