css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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>
  <div class="headline">
    <p>Number of Unique Users per Day (Aug - Oct 2015) </p>
  </div>
  <div id="main">
    <div class="chart-container">
      <p id="chart"></p>
    </div>
    <div class="legend">
      <div id="application-1">
        Application 1
      </div>
      <div id="application-2">
        Application 2
      </div>
    </div>
  </div>
</div>
            
          
!
            
              html,
body {
  background: #2b2b2b;
  font-family: 'Unica One', sans-serif;
  font-size: 12px;
}

#chart {
  margin-left: 10px;
}

text {
  font: 12px 'Unica One' sans-serif;
  fill: #b3b3b3;
}

.tick text {
  font-size: 15px;
}

.headline {
  font: 26px sans-serif;
  color: #fff;
  text-align: center;
  width: 1200px;
  margin: 15px;
}

.dot {
  stroke: #000;
}

.axis path {
  fill: none;
  stroke: #737373;
  stroke-width: 2;
  shape-rendering: crispEdges;
}

.y.axis path {
  opacity: 0;
}

.axis line {
  stroke: #737373;
}

.chart-line.application-1 {
  stroke: #2B908F;
  fill: none;
}

.chart-line.application-2 {
  stroke: #90EE7E;
  fill: none;
}

circle.application-1 {
  fill: #2B908F;
}

circle.application-2 {
  fill: #90EE7E;
}

@keyframes fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.2;
  }
}

.fading {
  animation-name: fade;
  animation-duration: 2s;
  opacity: 0.2;
}

.regression-line {
  stroke-width: 4;
  box-shadow: 0 0 8px #ea4c89, inset 0 0 8px #ea4c89;
}

.regression-line.tvair {
  stroke: #237675;
}

.regression-line.netflix {
  stroke: #38cb1b;
}

.chart-container {
  float: left;
  width: 80%;
  max-width: 1060px;
}

.legend {
  /*background:rgba(0, 0, 0, 0.0);*/
  box-sizing: border-box;
  border-radius: 9px;
  margin-left: 20px;
  float: left;
  width: 20%;
  max-width: 220px;
}

.legend div {
  margin: 10px;
  padding: 10px;
  border-radius: 9px;
  color: #d9d9d9;
  font-weight: bold;
  font-size: 15px;
}

#application-1 {
  background: rgba(43, 144, 143, 0.9);
}

#application-2 {
  background: rgba(144, 238, 126, 0.7);
}

.logo {
  display: inline;
  border-radius: 10px;
  width: 48px;
  height: 48px;
}
            
          
!
            
              var desiredWith = 1050;
documentWidth = desiredWith;

var margin = {
    top: 19.5,
    right: 0,
    bottom: 30,
    left: 60
  },
  width = documentWidth - margin.right - margin.left,
  height = 700 - margin.top - margin.bottom;

var widthScaleFactor = Math.min(documentWidth / desiredWith, 1.0);

var xScale = d3.time.scale().domain([new Date(2015, 7, 4), new Date(2015, 9, 30)]).nice(d3.time.day, 10).range([0, width]), // data traffic
  yScale = d3.scale.linear().domain([2000, 12000]).range([height, 0]), // start times
  radiusScale = d3.scale.sqrt().domain([0, 106]).range([1, 40]); // no of user
colorScale = d3.scale.category10(); // categories

var xAxis = d3.svg.axis().orient("bottom").scale(xScale).tickFormat(d3.time.format("%b %d")).tickSize(10),
  yAxis = d3.svg.axis().scale(yScale).orient("left");

svg = d3.select("#chart").append("svg")
  .attr("width", width + margin.left + margin.right)
  .attr("height", height + margin.top + margin.bottom)
  .append("g")
  .attr("transform", "scale(" + widthScaleFactor + ")")
  .append("g")
  .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

// Add the x-axis.
svg.append("g")
  .attr("class", "x axis")
  .attr("transform", "translate(0," + height + ")")
  .call(xAxis);

d3.select('.axis.x') // add line
  .selectAll('line')
  .data(xScale.ticks(d3.time.day, 1), function(d) {
    return d;
  })
  .enter().append('line')
  .attr('class', 'day-ticks')
  .attr('y1', 0)
  .attr('y2', 5)
  .attr('x1', xScale)
  .attr('x2', xScale);

// Add the y-axis.
svg.append("g")
  .attr("class", "y axis")
  .call(yAxis);

d3.select('.axis.y')
  .selectAll('line')
  .attr("x2", width);

var bisect = d3.bisector(function(d) {
  return d[0];
});

function animate(callback, duration) { // animate calls callback every frame for the specified duration
  var start = Date.now();
  var wrapper = function() {
    var elapsedTime = Date.now() - start;
    callback(elapsedTime / duration);
    if (elapsedTime <= duration)
      requestAnimationFrame(wrapper);
  }
  requestAnimationFrame(wrapper);
}

var tickTime = 145;

function tick(callback) { // invoke callback function every tickTime and stop when it returns true
  var completed = callback();
  if (!completed) {
    var nextTick = tick.bind(this, callback);
    setTimeout(nextTick, tickTime);
  }
}

data = {
  "application-1": [
    ["2015-08-04T00:00:00", 4524],
    ["2015-08-05T00:00:00", 4289],
    ["2015-08-06T00:00:00", 5778],
    ["2015-08-07T00:00:00", 5093],
    ["2015-08-08T00:00:00", 3631],
    ["2015-08-09T00:00:00", 4844],
    ["2015-08-10T00:00:00", 4105],
    ["2015-08-11T00:00:00", 5459],
    ["2015-08-12T00:00:00", 5599],
    ["2015-08-13T00:00:00", 5346],
    ["2015-08-14T00:00:00", 4707],
    ["2015-08-15T00:00:00", 3333],
    ["2015-08-16T00:00:00", 3816],
    ["2015-08-24T00:00:00", 4525],
    ["2015-08-27T00:00:00", 5478],
    ["2015-08-28T00:00:00", 5373],
    ["2015-08-29T00:00:00", 4047],
    ["2015-09-03T00:00:00", 6438],
    ["2015-09-04T00:00:00", 4220],
    ["2015-09-08T00:00:00", 5298],
    ["2015-09-09T00:00:00", 5463],
    ["2015-09-11T00:00:00", 5495],
    ["2015-09-12T00:00:00", 4648],
    ["2015-09-13T00:00:00", 5921],
    ["2015-09-14T00:00:00", 6299],
    ["2015-09-15T00:00:00", 5912],
    ["2015-09-16T00:00:00", 7593],
    ["2015-09-17T00:00:00", 6698],
    ["2015-09-18T00:00:00", 7256],
    ["2015-09-19T00:00:00", 4919],
    ["2015-09-20T00:00:00", 6549],
    ["2015-09-21T00:00:00", 6949],
    ["2015-09-22T00:00:00", 5871],
    ["2015-09-23T00:00:00", 5550],
    ["2015-09-24T00:00:00", 5468],
    ["2015-09-27T00:00:00", 6065],
    ["2015-09-29T00:00:00", 6037],
    ["2015-09-30T00:00:00", 6666],
    ["2015-10-01T00:00:00", 6674],
    ["2015-10-02T00:00:00", 6426],
    ["2015-10-03T00:00:00", 5191],
    ["2015-10-04T00:00:00", 4298],
    ["2015-10-05T00:00:00", 5571],
    ["2015-10-06T00:00:00", 7133],
    ["2015-10-07T00:00:00", 6576],
    ["2015-10-08T00:00:00", 5363],
    ["2015-10-09T00:00:00", 6761],
    ["2015-10-10T00:00:00", 4638],
    ["2015-10-11T00:00:00", 5243],
    ["2015-10-12T00:00:00", 6092],
    ["2015-10-13T00:00:00", 7173],
    ["2015-10-14T00:00:00", 7612],
    ["2015-10-15T00:00:00", 6573],
    ["2015-10-16T00:00:00", 6517],
    ["2015-10-17T00:00:00", 5222],
    ["2015-10-18T00:00:00", 6615],
    ["2015-10-19T00:00:00", 7569],
    ["2015-10-20T00:00:00", 7435],
    ["2015-10-21T00:00:00", 6172],
    ["2015-10-22T00:00:00", 5797],
    ["2015-10-28T00:00:00", 6630]
  ],
  "application-2": [
    ["2015-08-04T00:00:00", 7067],
    ["2015-08-05T00:00:00", 6388],
    ["2015-08-06T00:00:00", 5244],
    ["2015-08-07T00:00:00", 5869],
    ["2015-08-08T00:00:00", 4853],
    ["2015-08-09T00:00:00", 4777],
    ["2015-08-10T00:00:00", 5511],
    ["2015-08-11T00:00:00", 6250],
    ["2015-08-12T00:00:00", 5734],
    ["2015-08-13T00:00:00", 6371],
    ["2015-08-14T00:00:00", 5452],
    ["2015-08-15T00:00:00", 4442],
    ["2015-08-16T00:00:00", 5802],
    ["2015-08-24T00:00:00", 6838],
    ["2015-08-27T00:00:00", 8534],
    ["2015-08-28T00:00:00", 6336],
    ["2015-09-02T00:00:00", 6153],
    ["2015-09-03T00:00:00", 8609],
    ["2015-09-04T00:00:00", 6633],
    ["2015-09-08T00:00:00", 9697],
    ["2015-09-09T00:00:00", 9398],
    ["2015-09-11T00:00:00", 8599],
    ["2015-09-12T00:00:00", 9302],
    ["2015-09-13T00:00:00", 10640],
    ["2015-09-14T00:00:00", 8660],
    ["2015-09-15T00:00:00", 10652],
    ["2015-09-16T00:00:00", 9708],
    ["2015-09-17T00:00:00", 10833],
    ["2015-09-18T00:00:00", 10657],
    ["2015-09-19T00:00:00", 8347],
    ["2015-09-20T00:00:00", 9868],
    ["2015-09-21T00:00:00", 8596],
    ["2015-09-22T00:00:00", 8575],
    ["2015-09-23T00:00:00", 9972],
    ["2015-09-24T00:00:00", 7643],
    ["2015-09-27T00:00:00", 7793],
    ["2015-09-29T00:00:00", 8272],
    ["2015-09-30T00:00:00", 8513],
    ["2015-10-01T00:00:00", 9514],
    ["2015-10-02T00:00:00", 7286],
    ["2015-10-03T00:00:00", 6580],
    ["2015-10-04T00:00:00", 8509],
    ["2015-10-05T00:00:00", 9253],
    ["2015-10-06T00:00:00", 8119],
    ["2015-10-07T00:00:00", 8235],
    ["2015-10-08T00:00:00", 8646],
    ["2015-10-09T00:00:00", 11039],
    ["2015-10-10T00:00:00", 9236],
    ["2015-10-11T00:00:00", 8939],
    ["2015-10-12T00:00:00", 10505],
    ["2015-10-13T00:00:00", 8967],
    ["2015-10-14T00:00:00", 8698],
    ["2015-10-15T00:00:00", 8860],
    ["2015-10-16T00:00:00", 8775],
    ["2015-10-17T00:00:00", 8521],
    ["2015-10-18T00:00:00", 9515],
    ["2015-10-19T00:00:00", 8825],
    ["2015-10-20T00:00:00", 10976],
    ["2015-10-21T00:00:00", 10290],
    ["2015-10-22T00:00:00", 9409],
    ["2015-10-28T00:00:00", 11554]
  ]
}

function x(d) {
  return d[0];
}

function y(d) {
  return d[1];
}

var addPointFunc = function(data) {
  var index = 0; // starting data index 
  var length = 0;
  for (var s in data) {
    if (data[s].length > length) length = data[s].length;
  }

  return function() {
    if (index >= length) return true;

    $.each(data, function(key, points) {
      var point = points[index];
      point[0] = new Date(Date.parse(point[0]));
      var pX = xScale(x(point));
      var pY = yScale(y(point));
      //meta[key].training.push([pX, pY]);

      var circle = svg.append("circle")
        .attr("class", "point " + key)
        .attr("cx", pX)
        .attr("cy", pY)
        .attr("r", 5);

      var glow = svg.append("circle")
        .attr("class", "glow " + key)
        .attr("cx", pX)
        .attr("cy", pY)
        .attr("r", 5);

      animate(function(t) { // animate the glowing effect of data point
        var newRadius = 5 + (30 - 5) * t;
        var newOpac = (1 - t) > 0 ? (1 - t) : 0;
        glow.attr("r", newRadius);
        glow.attr("fill-opacity", newOpac);
      }, 500);

      if (index == 0) {
        svg.append("path")
          .attr("class", "chart-line " + key)
          .attr("d", "M " + pX + " " + pY);
      } else {
        var path = svg.select(".chart-line." + key);
        var d = path.attr("d");
        path.attr("d", d + " L " + pX + " " + pY);

      }

    });
    index++;
    return false;
  }
}

var addPoint = addPointFunc(data);
tick(addPoint);
            
          
!
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.
Loading ..................

Console