Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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.


Auto Save

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.


                <h1>US Agriculture Production by State, with the 50 largest cities</h1>


                body {
	background: #222;

h1 {
	text-align: center;
	color: white;
	font-family: sans-serif;
	font-size: 2em;
	margin: 1em 0;


                var width = 960,
    height = 500;

var color = d3.scaleQuantize()

var projection = d3.geoAlbersUsa()
                   .translate([width/2, height/2])
var path = d3.geoPath()

var svg ="body").append("svg")
    .attr("width", width)
    .attr("height", height);

d3.csv('', function(error, data) {
	if(error) throw error;
		d3.min(data, function(d) { return d.value; }),
		d3.max(data, function(d) { return d.value; })

	d3.json("", function(error, json) {

		// Merge the ag. data and GeoJSON
		// Loop through once for each ag. data value
		for (var i = 0, max = data.length; i < max; i++) {
			// grab state name
			var dataState = data[i].state;
			// grab data value, and convert from string to float
			var dataValue = parseFloat(data[i].value);
			// Find the corresponding state inside the GeoJSON
			for( var j = 0, jmax = json.features.length; j < jmax; j++) {
				var jsonState = json.features[j];
				if(dataState == jsonState) {
					// copy the data value into the JSON
					json.features[j].properties.value = dataValue;
					// stop looking through the JSON
      .attr("d", path)
		  .style('stroke', 'white')
	    .style('fill', function(d) {
				// get data value
			  var value =;
				if(value) {
					// if value exists
					return color(value);
				} else {
					// if value is undefined...
					return "#ccc";
		d3.csv("", function(data) {
			   .attr('cx', function(d) {
				 		return projection([d.lon,])[0];
			   .attr('cy', function(d) {
				    return projection([d.lon,])[1];
			   .attr('r', function(d) {
				    return Math.sqrt(parseInt(d.population) * 0.00004);
			   .style('fill', 'yellow')
			   .style('opacity', 0.75);