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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

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







//defining Margins
    var margin = {top: 40, right: 40, bottom: 100, left: 40},
        width = 700 - margin.left - margin.right,
        height = 500 - - margin.bottom;

// SVG
	var svg ="body")
	    .attr("transform", "translate("+margin.left+","")");
 //var pathToCsv = "boardgame_ratings.csv"; 

var color = d3.scaleOrdinal(d3.schemeCategory10)

var line = d3.line()
  .x(function(d) { return x(d.key); })
  .y(function(d) { return y(d.value); }); 

 //Get data
 d3.dsv(",", "average-rating.csv", function(d){
    return {
    	,year: d.year
    	, average_rating: Math.floor(d.average_rating)
    	, users_rated: +d.users_rated

var	filterData = data.filter(function(d){
	 if (d["year"] == "2015" || d["year"] == "2016" ||d["year"] == "2017" ||d["year"] == "2018" ||d["year"] == "2019" ||d["year"] == "2020" ) {
	 	return d;


	//var gdata = filterData

	 grouped_ratings = d3.nest()
	 //.key(function(d){return d.average_rating;}).sortKeys(d3.ascending)
	  .key(function(d){return d.year;}).sortKeys(d3.ascending)
	   .key(function(d){return d.average_rating;}).sortKeys(d3.ascending)
		  // .rollup(function(cntrev){return{"cntrev":cntrev, "ratings": d3.sum(cntrev, function(d){
		 	// return parseInt(filterData.average_rating);

		  .rollup(function(occ){return{"average_rating":occ[0].average_rating,"occ":occ,"tot_rat":d3.sum(occ,function(d){return parseInt(d.average_rating);})}})

var xScale =d3.scaleTime()
	.domain(d3.extent(data, function(d){
            return new Date(parseInt(filterData.year),0);})); 

var yScale =d3.scaleLinear()
	// .domain(0,d3.max(grouped_ratings, function(d){
	// 	return d3.average_rating

var graph = svg.selectAll(".line.path")
      .attr("class", "graph")

var xAxis = d3.axisBottom()
var yAxis = d3.axisLeft()
    .attr("transform", "translate("+ 50+"," + (height) + ")") //use variable in translate
    .attr("transform", "rotate(-90)")
    .attr("x", "475")
    .attr("y", "50")
    .attr("text-anchor", "end")

    .attr("class", "yAxis")
    .attr("id", "yAxis")
    .attr("transform", "translate(50,20)") //use variable in translate
    .attr("transform", "rotate(-90)")
    .attr("x", "100")
    .attr("y", "-100")
    .attr("text-anchor", "end")
    //} );

var lineGen = d3.line()
  .x(function(d) {
    return xScale(d.year);
  .y(function(d) {
    return yScale(d.tot_rat);


//X and y scales