Skip to content

Commit

Permalink
resized chart and selected top 10 sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-leou committed Jan 15, 2024
1 parent 59afa3a commit b3a6771
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions state_sectors/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,15 @@ function updateBarChart(data, selectedState) {
}

const margin = { top: 80, right: 30, bottom: 300, left: 110 };
const width = 1200 - margin.left - margin.right; // Increase the width
const width = 600 - margin.left - margin.right; // Increase the width
const height = 600 - margin.top - margin.bottom;

// Clear the contents of #chart-container
d3.select("#chart-container").html("");

// Take only the top 10 sectors
const top10Data = data.slice(0, 10);

// Create a new SVG
svg = d3.select("#chart-container")
.append("svg")
Expand All @@ -112,19 +115,19 @@ function updateBarChart(data, selectedState) {
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

const x = d3.scaleBand()
.domain(data.map(d => d.NAICS_Description))
.domain(top10Data.map(d => d.NAICS_Description))
.range([0, width])
.padding(0.2) // Adjust the padding for better separation
.align(0.5); // Align the bars to the center of the band

const y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.TotalPayroll)])
.domain([0, d3.max(top10Data, d => d.TotalPayroll)])
.nice()
.range([height, 0]);

svg.append("g")
.selectAll("rect")
.data(data)
.data(top10Data)
.enter()
.append("rect")
.attr("x", d => x(d.NAICS_Description) + 5)
Expand Down

0 comments on commit b3a6771

Please sign in to comment.