cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="wrapper">
  <div class="content">
    <h1>Fitbit Steps</h1>
    <h2>March - May 2016</h2>
  </div>
</div>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
            
          
!
            
              body {
      font-family: "Avenir", "Helvetica Neue", Helvetica, sans-serif;
      width: 100%;
      color: #000;
    }
    h1, h2 {
      text-transform: uppercase;
      text-align: center;
    }
    h1 {
      font-size: 48px;
      margin-top: 30px;
      margin-bottom: 0px;
    }
    h2 {
      font-size: 28px;
      color: #888;
    }

    /* SVG */
    svg.main {
      display: block;
      margin: 0 auto;
      margin-top: 30px;
    }
    .axis path,
    .axis line {
      fill: none;
      stroke: #000;
      shape-rendering: crispEdges;
    }
    .x.axis path {
      display: none;
    }
    .line {
      fill: none;
      stroke: #58C9B9;
      stroke-width: 1.5px;
    }
            
          
!
            
              var margin = { top: 20, right: 20, bottom: 30, left: 50 };
var width = 960 - margin.left - margin.right;
var height = 600 - margin.top - margin.bottom;
var xOffset = 10; // make room for y axis labels

var formatDate = d3.time.format("%m/%d/%Y");


var data = [
 {
   "date":"3/1/2016",
   "steps":9568
 },
 {
   "date":"3/2/2016",
   "steps":12300
 },
 {
   "date":"3/3/2016",
   "steps":10655
 },
 {
   "date":"3/4/2016",
   "steps":11966
 },
 {
   "date":"3/5/2016",
   "steps":10115
 },
 {
   "date":"3/6/2016",
   "steps":10922
 },
 {
   "date":"3/7/2016",
   "steps":9476
 },
 {
   "date":"3/8/2016",
   "steps":13225
 },
 {
   "date":"3/9/2016",
   "steps":8623
 },
 {
   "date":"3/10/2016",
   "steps":9834
 },
 {
   "date":"3/11/2016",
   "steps":11039
 },
 {
   "date":"3/12/2016",
   "steps":9320
 },
 {
   "date":"3/13/2016",
   "steps":8227
 },
 {
   "date":"3/14/2016",
   "steps":13412
 },
 {
   "date":"3/15/2016",
   "steps":13844
 },
 {
   "date":"3/16/2016",
   "steps":10855
 },
 {
   "date":"3/17/2016",
   "steps":8144
 },
 {
   "date":"3/18/2016",
   "steps":9880
 },
 {
   "date":"3/19/2016",
   "steps":27707
 },
 {
   "date":"3/20/2016",
   "steps":20189
 },
 {
   "date":"3/21/2016",
   "steps":15109
 },
 {
   "date":"3/22/2016",
   "steps":15911
 },
 {
   "date":"3/23/2016",
   "steps":10024
 },
 {
   "date":"3/24/2016",
   "steps":12839
 },
 {
   "date":"3/25/2016",
   "steps":11484
 },
 {
   "date":"3/26/2016",
   "steps":4081
 },
 {
   "date":"3/27/2016",
   "steps":10963
 },
 {
   "date":"3/28/2016",
   "steps":12677
 },
 {
   "date":"3/29/2016",
   "steps":9698
 },
 {
   "date":"3/30/2016",
   "steps":14525
 },
 {
   "date":"3/31/2016",
   "steps":15595
 },
 {
   "date":"4/1/2016",
   "steps":13875
 },
 {
   "date":"4/2/2016",
   "steps":15870
 },
 {
   "date":"4/3/2016",
   "steps":10918
 },
 {
   "date":"4/4/2016",
   "steps":14569
 },
 {
   "date":"4/5/2016",
   "steps":12664
 },
 {
   "date":"4/6/2016",
   "steps":10654
 },
 {
   "date":"4/7/2016",
   "steps":7231
 },
 {
   "date":"4/8/2016",
   "steps":10276
 },
 {
   "date":"4/9/2016",
   "steps":18445
 },
 {
   "date":"4/10/2016",
   "steps":23428
 },
 {
   "date":"4/11/2016",
   "steps":12324
 },
 {
   "date":"4/12/2016",
   "steps":8790
 },
 {
   "date":"4/13/2016",
   "steps":13733
 },
 {
   "date":"4/14/2016",
   "steps":8621
 },
 {
   "date":"4/15/2016",
   "steps":12502
 },
 {
   "date":"4/16/2016",
   "steps":15360
 },
 {
   "date":"4/17/2016",
   "steps":19840
 },
 {
   "date":"4/18/2016",
   "steps":9134
 },
 {
   "date":"4/19/2016",
   "steps":10826
 },
 {
   "date":"4/20/2016",
   "steps":10681
 },
 {
   "date":"4/21/2016",
   "steps":11370
 },
 {
   "date":"4/22/2016",
   "steps":9133
 },
 {
   "date":"4/23/2016",
   "steps":13497
 },
 {
   "date":"4/24/2016",
   "steps":7838
 },
 {
   "date":"4/25/2016",
   "steps":13110
 },
 {
   "date":"4/26/2016",
   "steps":10187
 },
 {
   "date":"4/27/2016",
   "steps":13051
 },
 {
   "date":"4/28/2016",
   "steps":8195
 },
 {
   "date":"4/29/2016",
   "steps":8203
 },
 {
   "date":"4/30/2016",
   "steps":24499
 },
 {
   "date":"5/1/2016",
   "steps":1534
 },
 {
   "date":"5/2/2016",
   "steps":12994
 },
 {
   "date":"5/3/2016",
   "steps":9636
 },
 {
   "date":"5/4/2016",
   "steps":9942
 },
 {
   "date":"5/5/2016",
   "steps":7873
 },
 {
   "date":"5/6/2016",
   "steps":11139
 },
 {
   "date":"5/7/2016",
   "steps":13083
 },
 {
   "date":"5/8/2016",
   "steps":5773
 },
 {
   "date":"5/9/2016",
   "steps":14949
 },
 {
   "date":"5/10/2016",
   "steps":10510
 },
 {
   "date":"5/11/2016",
   "steps":15204
 },
 {
   "date":"5/12/2016",
   "steps":10860
 },
 {
   "date":"5/13/2016",
   "steps":12282
 },
 {
   "date":"5/14/2016",
   "steps":10208
 },
 {
   "date":"5/15/2016",
   "steps":16872
 },
 {
   "date":"5/16/2016",
   "steps":8663
 },
 {
   "date":"5/17/2016",
   "steps":9076
 },
 {
   "date":"5/18/2016",
   "steps":8388
 },
 {
   "date":"5/19/2016",
   "steps":8079
 },
 {
   "date":"5/20/2016",
   "steps":10727
 },
 {
   "date":"5/21/2016",
   "steps":9864
 },
 {
   "date":"5/22/2016",
   "steps":671
 },
 {
   "date":"5/23/2016",
   "steps":15407
 },
 {
   "date":"5/24/2016",
   "steps":13675
 },
 {
   "date":"5/25/2016",
   "steps":12143
 },
 {
   "date":"5/26/2016",
   "steps":14331
 },
 {
   "date":"5/27/2016",
   "steps":11585
 },
 {
   "date":"5/28/2016",
   "steps":17919
 },
 {
   "date":"5/29/2016",
   "steps":4835
 },
 {
   "date":"5/30/2016",
   "steps":1401
 },
 {
   "date":"5/31/2016",
   "steps":0
 }
];

for (var i = 0; i < data.length; i++) {
  data[i].date = formatDate.parse(data[i].date);
  data[i].steps = +data[i].steps;
}

var x = d3.time.scale()
  .range([0, width]);

var y = d3.scale.linear()
  .range([height, 0]);

var xAxis = d3.svg.axis()
  .scale(x)
  .ticks(d3.time.weeks, 2)
  .orient("bottom");

var yAxis = d3.svg.axis()
  .scale(y)
  .orient("left");

var line = d3.svg.line()
  .x(function(d) { return x(d.date); })
  .y(function(d) { return y(d.steps); });

var svg = d3.select(".wrapper")
  .append("svg")
  .attr("class", "main")
  .attr("width", width + margin.left + margin.right)
  .attr("height", height + margin.top + margin.bottom)
  .append("g")
  .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

x.domain(d3.extent(data, function(d) { return d.date; }));
y.domain([0, 30000]);
// y.domain([0, d3.max(data, function(d) { return d.steps; })]);

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

// Render y axis
svg.append("g")
  .attr("class", "y axis")
  .attr("transform", "translate( " + xOffset + ", 0)")
  .call(yAxis)
  .append("text")
  .attr("transform", "rotate(-90)")
  .attr("y", 6)
  .attr("dy", ".71em")
  .style("text-anchor", "end")
  .text("Steps");

svg.append("path")
  .datum(data)
  .attr("class", "line")
  .attr("transform", "translate( " + xOffset + ", 0)")
  .attr("d", line);

            
          
!
999px
Loading ..................

Console