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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div style="text-align:left; width:1900px; margin-left:60px">
<h1>The Free Code Camp Top10 (plus 1...) Main Chatroom Guardians</h1>
<h3>A quick view of the most active users and some statistics of the main chat, mostly from Jan 2015 until May 2016</h3>
</div>
<div id='chart1' style="margin-left:110px"></div>
<div id='chart2' style="margin-left:0px"></div>
<div id='chart3' style="margin-left:50px"></div>
<div id='useddata'></div>
            
          
!
            
              .line {
  fill: none;
  stroke: steelblue;
  stroke-width: 1.5px;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

body {
  font: 10px sans-serif;
}

#chart3 rect {
  fill: steelblue;
}

            
          
!
            
              
$(window).ready(function(){
    d3.json('https://gist.githubusercontent.com/evaristoc/267b074e7898eb85b78d2e2a9adc33e3/raw/1ab7aac5ae7724823f5b774e2327c5347a2a4595/chatdata.json', function(e,data){
        if(e){console.log("Error getting the json file...")};
        if(data){console.log("YES!!")};
      
     var data_top10 = data[0];
     var data_chatstats = data[1];

//////////////////////////////////////////////
// LISTS OF USERS
//////////////////////////////////////////////


        var margin = {top: 20, left: 50, bottom: 20, right: 20},
            height1 = 350 - margin.top - margin.bottom,
            width1 = 1790 - margin.left - margin.right;
        
        var svg1 = d3.select("#chart1").append("svg")
                    .attr("width", width1 + margin.left + margin.right)
                    .attr("height", height1 + margin.top + margin.bottom)
                    .append("g")
                    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

        var xscale1 = d3.scale.ordinal().domain(data_top10.map(function(d){return d.date}),[]).rangePoints([0,width1]);
        
        var yscale1 = d3.scale.linear().domain(d3.range(0,10)).range([height1, 0]);
        
           
        var imgurl = "http://wallpapers.androlib.com/wallicons/wallpaper.big-pqC.cs.png"
        
        
        var text = svg1.selectAll("text")
            .data(data_top10)
            .enter()
            .append("text")
            .attr("x", function(d, i){
                return xscale1(d.date) - 37;
            })
            .attr("y", function(d, i) {
                return height1 - yscale1((11 - d.ranking)/11);
            })
            .attr("font-size","9px")
            .text(function(d){return d.user})


//////////////////////////////////////////////
// LINES AND POINTS
//////////////////////////////////////////////

        
        var height2 = 100 - margin.top - margin.bottom;
        var width2 = 1900 - margin.left - margin.right - 10;
 

        var svg2 = d3.select("#chart2").append("svg")
                    .attr("width", width2 + margin.left + margin.right)
                    .attr("height", height2 + margin.top + margin.bottom)
                    .append("g")
                    .attr("transform", 
                    "translate(" + (margin.left + 100) + "," + margin.top + ")");


        var xscale2 = d3.scale.ordinal().domain([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]).rangePoints([0,width2]);
        
 
        var yscale2 = d3.scale.linear()
                        .domain(d3.extent(data_chatstats,function(d){return d.totmsgs}))
                        .range([height2,0]);
        
       
        var yAxis2 = d3.svg.axis()
            .scale(yscale2)
            .orient("left")
            .ticks(4);


        var xscale3 = d3.scale.identity()
            .domain([0, width2]);

           
        var xAxis3 = d3.svg.axis()
            .scale(xscale3)
            .ticks(0)
            .orient("bottom");        
        
            
        var line = d3.svg.line()
            .x(function(d,i) { //console.log(i);
                            return xscale1(d.date); })
            .y(function(d,i) { //console.log(ymscale(d.totmsgs));
                             return yscale2(d.totmsgs); });
           
            
        svg2.append("path")
            .datum(data_chatstats)
            .attr("class", "line")
            .attr("d", line)
            .attr({
                fill: "none",
                stroke: "steelblue",
                "stroke-width": "1.5px",    
            })

            
        svg2.append("g")
            .attr("class", "x axis")
            .attr("transform", "translate(0," + height2 + ")")
            .call(xAxis3);


        svg2.append("g")
            .attr("class", "y axis")
            .attr("transform","translate(-30,0)")
            .call(yAxis2)
            .append("text")
            .attr("transform", "rotate(-90)")
            .attr("y", 6)
            .attr("dy", ".71em")
            .style("text-anchor", "end")
            .text("num. msgs");

        
        var circles = svg2
                        .append("g")
                        .attr('class','.points')
                        .selectAll('circle')
                        
        circles
                .data(data_chatstats)
                .enter()
                .append('circle')
                .attr('cx', function(d,i){{return xscale1(d.date)}})
                .attr('cy', function(d,i){return yscale2(d.totmsgs)})
                .attr('r', '3')
                .attr('fill','slateblue')
        

//////////////////////////////////////////////
// BARS
//////////////////////////////////////////////

        var width3 = 1900 - margin.left - margin.right;
        
        var width4 = 1800 - margin.left - margin.right;

        
        var svg3 = d3.select("#chart3").append("svg")
                    .attr("width", width2 + margin.left + margin.right)
                    .attr("height", height2 + margin.top + margin.bottom)
                    .append("g")
                    .attr("transform", 
                    "translate(" + margin.left + "," + margin.top + ")");


        var xscale4 = d3.scale.ordinal().domain(data_chatstats.map(function(d){return d.date}),[]).rangePoints([0,width4]);


        var yscale4 = d3.scale.linear()
                        .domain(d3.extent(data_chatstats,function(d){return d.totpar}))
                        .range([height2,0]);
   
    
        var yAxis4 = d3.svg.axis()
            .scale(yscale4)
            .orient("left")
            .ticks(4);

        var formatXaxis4 = function(timestamp){
            timestamp = parseInt(timestamp);
            var date = new Date(timestamp*1000);
            var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
            
            return date.getFullYear()+"-"+months[date.getMonth()];
        
        }
        
        var xAxis4 = d3.svg.axis()
            .scale(xscale4)
            .tickFormat(formatXaxis4)
            //.ticks(1)
            .orient("bottom");        
        

        var barWidth = width3 / data_chatstats.length;
        
        
        
        var bar = svg3.selectAll("g")
                    .data(data_chatstats)
                    .enter().append("g")
                    .attr("transform", function(d, i) { return "translate(" + i * barWidth + ",0)"; });
        
        bar.append("rect")
                .attr("y", function(d) { return yscale4(d.totpar); })
                .attr("height", function(d) { return height2 - yscale4(d.totpar); })
                .attr("width", barWidth - 1);
        
        bar.append("text")
                .attr("x", barWidth / 2)
                .attr("y", function(d) { return yscale4(d.totpar) - 10; })
                .attr("dy", ".75em")
                .text(function(d) { return d.totpar; });


        svg3.append("g")
            .attr("class", "x axis")
            .attr("transform", "translate(50," + (height2) + ")")
            .call(xAxis4);            
    
        svg3.append("g")
            .attr("class", "y axis")
            .attr("transform","translate(20,-10)")
            .call(yAxis4)
            .append("text")
            .attr("transform", "rotate(-90)")
            .attr("y", 6)
            .attr("dy", ".71em")
            .style("text-anchor", "end")
            .text("num. users");
 

        
    })
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console