Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div class="big-chart-container">
  <div id="big-chart"></div>
</div>
              
            
!

CSS

              
                .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;
}
              
            
!

JS

              
                // 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

Console