Visualize Data with a Heat Map

Developer
Size
6,445 Kb
Views
10,120

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 Previews

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) + ' &#8457 / ' + (baseTemp + d.variance).toFixed(2) + ' &#8451</span><br><span class="variance">variance: ' + (d.variance * 1.8 + 32).toFixed(1) + ' &#8457 / ' + d.variance.toFixed(2) + ' &#8451</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'));
Visualize Data with a Heat Map - Script Codes
Visualize Data with a Heat Map - Script Codes
Home Page Home
Developer Codoer
Username c0d0er
Uploaded December 07, 2022
Rating 3
Size 6,445 Kb
Views 10,120
Do you need developer help for Visualize Data with a Heat Map?

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!

Codoer (c0d0er) Script Codes
Create amazing captions with AI!

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!