Data Visualization - US GDP
How do I make an data visualization - us gdp?
Fulfill the below user stories. User Story: I can see US Gross Domestic Product by quarter, over time.. What is a data visualization - us gdp? How do you make a data visualization - us gdp? This script and codes were developed by Sam Koshy on 14 January 2023, Saturday.
Data Visualization - US GDP - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Data Visualization - US GDP</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="chartTitle"><h1>US Gross Domestic Product</h1></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/d3/4.9.1/d3.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Data Visualization - US GDP - Script Codes CSS Codes
.chartTitle{ text-align:center
}
svg{ display: block; margin:-40px auto;
}
.bar:hover{ fill:#AA3939;
}
.tooltip{ position:absolute; width: auto; line-height: 0.01; padding-left:5px; padding-right:5px; border-radius:10px; font-family:Helvetica; background: #BCD9D9; white-space: nowrap; /*nowrap avoids a line break when approaching the window margin on right*/
}
Data Visualization - US GDP - Script Codes JS Codes
const w = 1000;
const h = 600;
const padding = 60;
const svg = d3.select("body").append("svg").attr("width", w).attr("height", h);
var month=["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
d3.json( "https://raw.githubusercontent.com/FreeCodeCamp/ProjectReferenceData/master/GDP-data.json", function(gdpData) { const barW = w / gdpData.data.length; const startDate = parseFloat(gdpData.from_date.substring(0, 4)) + parseFloat(gdpData.from_date.substring(5, 7)) / 12; const endDate = parseFloat(gdpData.to_date.substring(0, 4)) + parseFloat(gdpData.to_date.substring(5, 7)) / 12; const xScale = d3 .scaleLinear() .domain([startDate, endDate]) .range([padding, w - padding]); const yScale = d3 .scaleLinear() .domain([0, d3.max(gdpData.data, (d) => d[1])]) .range([h - padding, padding]); const xAxis = d3.axisBottom(xScale).tickFormat(d3.format("")); //d3.format("") or ("s") produces a number without comma delimiters const yAxis = d3.axisLeft(yScale); const tooltip = d3 .select("body") .append("div") .attr("class", "tooltip") .style("visibility", "hidden"); svg .selectAll("rect") .data(gdpData.data) .enter() .append("rect") .attr("x", (d) => xScale( parseFloat(d[0].substring(0, 4)) + parseFloat(d[0].substring(5, 7)) / 12 ) ) .attr("y", (d) => yScale(d[1])) .attr("width", barW) .attr("height", (d) => h - padding - yScale(d[1])) .style("fill", "#226666") .attr("class", "bar") //for hover effect .on("mouseover", (d, i) => { tooltip .style("visibility", "visible") .html( "<h4> $" + d[1].toLocaleString() + " Billion</h4> <p style='font-size:15px;'>" + month[parseInt(d[0].substring(5, 7))-1]+ ", " + d[0].substring(0, 4) + "</p>" );//toLocaleString() adds comma delimiters to d[1] numbers $("body").mousemove(function(e) { tooltip .style("top", e.pageY - 30 + "px") .style("left", 10 + e.pageX + "px"); });//e.pageX and e.pageY provide the position of pointer }) .on("mouseout", (d, i) => { tooltip.style("visibility", "hidden"); }); svg .append("g") .attr("transform", "translate(0, " + (h - padding) + ")") .style("font-size", "15px") .call(xAxis); svg .append("g") .attr("transform", "translate(" + (padding + 0) + ", 0)") .style("font-size", "15px") .call(yAxis); svg .append("text") .attr("x", w / 2) .attr("text-anchor", "middle") .attr("transform", "translate(0, " + (h - padding / 4) + ")") .style("font-size", "20px") .text("Year"); svg .append("text") .attr("x", -padding - 1) .attr("y", padding + 20) .attr("text-anchor", "end") .attr("transform", "translate(" + 0 + ", 0)rotate(-90)") .style("font-size", "20px") .text("Units: Billions of Dollars"); }
);
Developer | Sam Koshy |
Username | codinger |
Uploaded | January 14, 2023 |
Rating | 3 |
Size | 3,131 Kb |
Views | 2,024 |
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 |
Javascript Calculator | 4,576 Kb |
Wikipedia Viewer | 4,681 Kb |
Tic Tac Toe | 5,797 Kb |
Simon | 4,744 Kb |
Local Weather App | 5,141 Kb |
Heat Map | 3,614 Kb |
Personal Portfolio Webpage | 8,383 Kb |
Camper News | 3,194 Kb |
Pomodoro Clock | 5,358 Kb |
Twitchtv Status | 4,663 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 |
Click handler test | Snapson | 2,329 Kb |
Avero - Collectieve LVVP Arbeidsongeschiktheidsverzekering - CSS - som | Frederiquebonink | 12,554 Kb |
Flat UI - Checkbox FIX | ARS | 2,663 Kb |
Playing with transition timing | Mattgrosswork | 1,993 Kb |
AngularJS Skills | Supro | 3,312 Kb |
Example SVGZ Data URI | Joeyhoer | 2,981 Kb |
My three.js practice | Esambino | 3,203 Kb |
Faux column absolute wrapper | Yurimorini | 1,823 Kb |
Simple checkbox style | Vncnz | 2,628 Kb |
Pink expansion tunnel | Vez | 1,738 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!