-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
133e502
commit 135923e
Showing
6 changed files
with
567,041 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Pie Chart Visualization</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Pie Chart Visualization</h1> | ||
<div id="chart-container"> | ||
<svg id="pie-chart"></svg> | ||
</div> | ||
</div> | ||
<script src="https://d3js.org/d3.v7.min.js"></script> | ||
<script src="script.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Define the dimensions of the SVG canvas and the radius of the pie chart | ||
const width = 400; | ||
const height = 400; | ||
const radius = Math.min(width, height) / 2; | ||
|
||
// Create an SVG element and append it to the chart-container div | ||
const svg = d3.select("#pie-chart") | ||
.attr("width", width) | ||
.attr("height", height) | ||
.append("g") | ||
.attr("transform", `translate(${width / 2}, ${height / 2})`); | ||
|
||
// Load your CSV data | ||
d3.csv("Data_Sheet.csv", function(data) { | ||
// Group the data by "NAICS Description" and calculate the sum of "Firms" for each group | ||
// console.log(data); | ||
const dataGrouped = d3.group(data, d => d.NAICS_Description); | ||
//dataGrouped.forEach((value, key, map) => { | ||
// value.forEach(d => { | ||
// d.Firms = parseInt(d.Firms); // Convert "Firms" to a number | ||
// }); | ||
}); | ||
|
||
// Create a color scale for the pie chart | ||
const colorScale = d3.scaleOrdinal(d3.schemeCategory10); | ||
|
||
// Create a pie generator | ||
const pie = d3.pie() | ||
.value(d => d3.sum(d.value, e => e.Firms)); // Use d.value to access the values within each group | ||
|
||
// Generate the pie chart data | ||
const pieData = pie(Array.from(dataGrouped)); // Convert the grouped data to an array | ||
|
||
// Create arcs for the pie chart segments | ||
const arc = d3.arc() | ||
.innerRadius(0) | ||
.outerRadius(radius); | ||
|
||
// Create a path for each pie chart segment | ||
const paths = svg.selectAll("path") | ||
.data(pieData) | ||
.enter() | ||
.append("path") | ||
.attr("d", arc) | ||
.attr("fill", (d, i) => colorScale(i)) | ||
.attr("stroke", "white") | ||
.style("stroke-width", "2px"); | ||
|
||
// Add tooltips | ||
paths.append("title") | ||
.text(d => `${d.data.key}: ${d.value} firms`); | ||
//}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters