Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <!-- <script src=""></script> -->
<div id="container">
  <h1 id="title">USA Education</h1>'
  <div id="description">People over 25, who have a bachelor degree or higher</div>
  <div id="visualization"></div>     


                @import url('');

* {
  margin: unset;
  margin: auto;
  padding: unset;

#container {
  text-align: center;
  margin-top: 1em;
  padding: 1em;
	font-family: Roboto, sans-serif;
	color: darkblue;

#description {
	padding: 1em;

.county:hover {
	fill: purple;

#tooltip {
  display: flex;
  position: absolute;
  background: darkblue;
  border: solid white 2px;
  border-radius: 5px;
  color: white;
  text-align: left;
  padding: 0.3em;
  font-family: arial;
  font-size: 12px;
  font-weight: bolder;


                //GET API Data
document.addEventListener("DOMContentLoaded", () => getDataMap());

const getDataMap = async() => {
    let responseCounty = await fetch("");
    const countyData = await responseCounty.json(); 
    let responseEducation = await fetch("");
    const educationData = await responseEducation.json();

    drawChart (countyData, educationData);
  } catch (error) {

const width = 1000;
const height = 700;

const margin = 50;
const padding = 30;

const svg ="#visualization")
              .attr("width", width)
              .attr("height", height);

const tooltip ="#visualization")
                  .attr("id", "tooltip")
                  .attr("class", "tooltip")
                  .style("opacity", 0);

const drawChart = (usMap, educationCountyData) => {

  //defining MIN and MAX Education Variables
  const [minEducation, maxEducation] = [...d3.extent( => eData.bachelorsOrHigher))];

  //defining x- and color Scales
  const xScale = d3.scaleLinear()
                   .domain([minEducation, maxEducation])
                   .rangeRound([0+margin, width-margin]);
  const color = d3.scaleThreshold()
                  .domain(d3.range(minEducation, maxEducation, (maxEducation-minEducation)/8))

	//filtering education data for the map
	let eduData = (datSet) => {
		let edu = educationCountyData.filter(data => data.fips === datSet)
		if (edu[0]) {
			return edu[0];
		return 0;
	//drawing the legend
	const dataStepsLegend = (maxEducation-minEducation)/8
	const dataLegend = [minEducation, minEducation+1*dataStepsLegend, minEducation+2*dataStepsLegend, minEducation+3*dataStepsLegend, minEducation+4*dataStepsLegend, minEducation+5*dataStepsLegend, minEducation+6*dataStepsLegend, maxEducation]
	const formatPercent = d3.format(".1%")
	const x = d3.scaleLinear()
							.domain([minEducation, maxEducation])
							.range([0, 300])
	const xAxis = d3.axisBottom(x)
									.tickFormat(d => formatPercent(d/100))
	const legend = svg.append("g")
										.attr("id", "legend")
				.attr("x", (d, i) => (width/2)+margin+(300/8*(i)))
				.attr("y", padding-20)
				.attr("width", 300/8)
				.attr("height", 20)
				.style("fill", color)	
	const legendValues =	svg.append("g")
										 		 	 .attr("id", "legendValues")
											 	 	 .attr("transform", `translate(${width/2+margin}, ${padding})`)

  //drawing the map
  const path = d3.geoPath();
     .attr("class", "counties")
     .data(topojson.feature(usMap, usMap.objects.counties).features)
     .attr("class", "county")
     .attr("data-fips", d =>
     .attr("data-education", d => eduData(
     .attr("fill", d => color(eduData(
     .attr("d", path)
     .on("mouseover", function(d, i){
"opacity", 0.8)
		      tooltip.html("Fips: " + 
											 eduData( "<br/>State: " +	
											 eduData( "<br/>Area: " +		
											 eduData( "<br/>Education: " +		
											 eduData( "%")
                 .style("left", d3.event.pageX+ 10 + "px")
                 .style("top", d3.event.pageY+ 5 + "px")
								 .attr("data-education", eduData(
     .on("mouseout", function(d){
"opacity", 0);