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 class="big-chart-container">
  <div id="big-chart"></div>
</div>
            
          
!
            
              .line {
  fill: none;
  stroke: #36B8BE;
  stroke-width: 1px;
  z-index: 2;
}

.area {
  fill: url(#area-gradient);
  stroke-width: 0;
  z-index: 1;
}

g text {
  font: 1.5rem 'avenir next', 'open sans', sans-serif;
  font-size: 24px;
}

g.tick line {
  stroke: #ccc;
}

g .tick text {
  fill: #444;
}

path.domain {
  stroke: #CCC;
}

.grid line {
  stroke: #aeb0b5;
  stroke-opacity: 0.7;
  stroke-width: .2vh;
  shape-rendering: crispEdges;
  z-index: -1;
}

.grid path {
  stroke-width: 0;
}

.data-point-label {
  font-weight: 600;
  font-size: 16px;
}

.y-axis-labels {
  fill: #CCC;
}
            
          
!
            
              // set the dimensions and margins of the graph
var margin = {
  top: 20,
  right: 60,
  bottom: 90,
  left: 90
},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

// parse the date / time
var parseTime = d3.timeParse("%A %B %d %Y %H");
var formatTime = d3.timeFormat("%a"); // %d

// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);

// define the line
var valueline = d3.line()
.x(function (d) {
  return x(d.date);
})
.y(function (d) {
  return y(d.progress);
});

// define the area
var area = d3.area()
.x(d => x(d.date))
.y0(y(0))
.y1(d => y(d.progress));

var div = d3.select("#big-chart-container").append("div")
.attr("class", "tooltip")
.style("opacity", 0);

format = d3.format(".0f")

// append the svg to the chart container
var bigChartSvg = d3.select("#big-chart").append("svg")
.attr("viewBox", "0 0 " + (width + margin.left + margin.right) + " " + (height + margin.top +
                                                                        margin.bottom))
.attr("preserveAspectRatio", "xMaxYMax meet")
.classed("svg-content", true)
.append("g")
.attr("transform",
      "translate(" + margin.left + "," + margin.top + ")");
// Get the data
var data = [
  {
    "date": "Monday March 12 2018 00",
    "progress": 8
  },
  {
    "date": "Monday March 12 2018 06",
    "progress": 11
  },
  {
    "date": "Monday March 12 2018 12",
    "progress": 9
  },
  {
    "date": "Monday March 12 2018 18",
    "progress": 11
  },
  {
    "date": "Tuesday March 13 2018 00",
    "progress": 19
  },
  {
    "date": "Tuesday March 13 2018 06",
    "progress": 21
  },
  {
    "date": "Tuesday March 13 2018 12",
    "progress": 19
  },
  {
    "date": "Tuesday March 13 2018 18",
    "progress": 21
  },
  {
    "date": "Wednesday March 14 2018 00",
    "progress": 23
  },
  {
    "date": "Wednesday March 14 2018 06",
    "progress": 28
  },
  {
    "date": "Wednesday March 14 2018 12",
    "progress": 24
  },
  {
    "date": "Wednesday March 14 2018 18",
    "progress": 34
  },
  {
    "date": "Thursday March 15 2018 00",
    "progress": 38
  },
  {
    "date": "Thursday March 15 2018 06",
    "progress": 38
  },
  {
    "date": "Thursday March 15 2018 12",
    "progress": 40
  },
  {
    "date": "Thursday March 15 2018 18",
    "progress": 40
  },
  {
    "date": "Friday March 16 2018 00",
    "progress": 40
  },
  {
    "date": "Friday March 16 2018 06",
    "progress": 48
  },
  {
    "date": "Friday March 16 2018 12",
    "progress": 52
  },
  {
    "date": "Friday March 16 2018 18",
    "progress": 62
  },
  {
    "date": "Saturday March 17 2018 00",
    "progress": 62
  },
  {
    "date": "Saturday March 17 2018 06",
    "progress": 59
  },
  {
    "date": "Saturday March 17 2018 12",
    "progress": 66
  },
  {
    "date": "Saturday March 17 2018 18",
    "progress": 78
  },
  {
    "date": "Sunday March 18 2018 00",
    "progress": 83
  },
  {
    "date": "Sunday March 18 2018 06",
    "progress": 84
  },
  {
    "date": "Sunday March 18 2018 12",
    "progress": 83
  },
  {
    "date": "Sunday March 18 2018 18",
    "progress": 83
  }
];

// format the data
data.forEach(function (d) {
  d.date = parseTime(d.date);
  d.progress = +d.progress;
});

// scale the range of the data
x.domain(d3.extent(data, function(d) { return (d.date); }));
y.domain([0, 100]);
//attach gradient to area
bigChartSvg.append("linearGradient")
  .attr("id", "area-gradient")
  .attr("gradientUnits", "userSpaceOnUse")
  .attr("x1", 0).attr("y1", y(0))
  .attr("x2", 0).attr("y2", y(100))
  .selectAll("stop")
  .data([{
    offset: "0%",
    color: "#3997A7",
    opacity: ".1"
  },
         {
           offset: "15%",
           color: "#3997A7",
           opacity: ".3"
         },
         {
           offset: "30%",
           color: "#3997A7",
           opacity: ".5"
         },
         {
           offset: "45%",
           color: "#3997A7",
           opacity: ".6"
         },
         {
           offset: "65%",
           color: "#36B8BE",
           opacity: ".7"
         },
         {
           offset: "80%",
           color: "#36B8BE",
           opacity: "1"
         }
        ])
  .enter().append("stop")
  .attr("offset", function (d) {
  return d.offset;
})
  .attr("stop-color", function (d) {
  return d.color;
})
  .attr("stop-opacity", function(d) {
  return d.opacity;
});

// Add the filled area
bigChartSvg.append("path")
  .datum(data)
  .attr("class", "area")
  .attr("d", area)
  .style("opacity", .5);

console.log([data]);
// add the valueline path.
bigChartSvg.append("path")
  .attr("class", "line")
  .attr("d", valueline(data));

// add the x axis
bigChartSvg.append("g")
  .attr("transform", "translate(0," + height + ")")
  .call(d3.axisBottom(x).tickFormat(d3.timeFormat("%a")).ticks(7))
  .selectAll("text")
  .attr("y", 0)
  .attr("x", 8)
  .attr("dy", "40")
  .attr("dx", "3.5%")
  .attr("transform", "rotate(0)") //60
  .style("text-anchor", "start");

// add the y axis
bigChartSvg.append("g")
  .call(d3.axisLeft(y).ticks(5));

// add y axis labels
bigChartSvg.append("text")
  .attr("transform", "rotate(-90)")
  .attr("y", 0 - margin.left)
  .attr("x",0 - (height / 2))
  .attr("dy", "1em")
  .style("text-anchor", "middle")
  .text("% Shift Goal");

bigChartSvg.append("g")
      .attr("fill", "#003A52")
      .attr("text-anchor", "end")
      .style("font", "4px avenir-next")
      .selectAll("text")
      .data(data)
      .enter().append("text")
      .classed("data-point-label",true)
      .attr("x", d => x(d.date))
      .attr("y", d => y(d.progress) - 12)
      .attr("dx", "0.35em")
      .attr("dy", "0.25em")
      .text(d => format(d.progress));
            
          
!
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