Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                <script>

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

// SVG
	var svg = d3.select("body")
	  .append("svg")
	    .attr("width",width+margin.left+margin.right)
	    .attr("height",height+margin.top+margin.bottom)
	    .append("g")
	    .attr("transform", "translate("+margin.left+","+margin.top+")");
 //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 {
    	name: d.name
    	,year: d.year
    	, average_rating: Math.floor(d.average_rating)
    	, users_rated: +d.users_rated
    };
}).then(function(data){

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;

	 }
	
		});

 console.log(filterData)
	//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);})}})
		
		
	 
		.entries(filterData)
		

console.log(grouped_ratings)
var xScale =d3.scaleTime()
	.range([0,width])
	.domain(d3.extent(data, function(d){
            return new Date(parseInt(filterData.year),0);})); 

var yScale =d3.scaleLinear()
	.range(height,0)
	.domain([0,700]);
	// .domain(0,d3.max(grouped_ratings, function(d){
	// 	return d3.average_rating
	//}));

var graph = svg.selectAll(".line.path")
      .attr("class", "graph")
     .data(grouped_ratings)
     .enter().append('path')
     

var xAxis = d3.axisBottom()
.scale(xScale)
.tickFormat(d3.timeFormat("%Y"))    
        .ticks(5);
var yAxis = d3.axisLeft()
    .scale(yScale)

 d3.select("svg").append("g")
    .attr("class","xAxis")
    .attr("transform", "translate("+ 50+"," + (height) + ")") //use variable in translate
    .call(xAxis)
    .append("text")
    .attr("transform", "rotate(-90)")
    .attr("x", "475")
    .attr("y", "50")
    .attr("text-anchor", "end")
    .text("Rating")


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

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

 console.log(grouped_ratings)
});


//X and y scales 




</script>
              
            
!
999px

Console