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.

              @import url('https://fonts.googleapis.com/css?family=Lato:300,900');

#emmys {
  font-family: "Lato";

#emmys .subject-ring {
  display: none;

div.title {
  font-size: 2em;
  width: 200px;
  position: absolute;
  left: 70px;
  top: 100px;
  line-height: 1.5em;
  color: "black";
  font-family: "Lato";

#emmys .annotation.badge text {
  font-weight: normal;
  font-size: 10px;

#emmys .annotation text {
  font-size: 0.7em;
  text-transform: uppercase;
  font-weight: bold;

.annotation.axis .annotation-note-bg {
  fill: white;
  stroke: white;
  stroke-width: 10;

.annotation.axis path {
  stroke: lightgrey;

.annotation.axis text {
  fill: lightgrey;

  function(error, { networkLines }) {
    const { AnnotationLabel, AnnotationBadge, AnnotationXYThreshold } = ReactAnnotation
    function LineChart() {
      const width = 960,
        height = 500,
        margin = { top: 30, right: 130, bottom: 50, left: 340 }

      const x = d3.scaleLinear()
        .range([margin.left, width - margin.right])
        .domain([2013, 2017])
      const y = d3.scaleLinear().range([height - margin.bottom, margin.top])

      y.domain([0, Math.max(...networkLines.map(d => d.max))])
      let lineGen = d3.line()
        .x(function(d) {
          return x(d.year)
        .y(function(d) {
          return y(d.value)

      const colors = {
        HBO: "black",
        Netflix: "#D32F2F",
        NBC: "#ffc107",
        "FX Networks": "#0097a7",
        ABC: "#00BFA5",
        CBS: "#00BCD4",
        FOX: "#3f51b5",
        Showtime: "#C5CAE9",
        AMC: "#D32F2F",
        PBS: "#B39DDB",
        Amazon: "#ffc107",
        "Nat Geo": "#ff9800",
        Hulu: "#00BFA5"
      const highlight = ["HBO", "Netflix"]

      const lines = networkLines
        .sort((a, b) => a.total - b.total)
        .map(d => (
            stroke={colors[d.network] || "grey"}
              highlight.indexOf(d.network) !== -1 ? "none" : "2, 4"

      /* Code below relevant for annotations */
      let previousNY = 0
      const labelAnnotations = networkLines
          //sort annotations by last data point for ordering
          (a, b) =>
            b.line[b.line.length - 1].value - a.line[a.line.length - 1].value
        .reduce((p, c) => {
          //push annotation down if it will overlap
          const ypx = y(c.line[c.line.length - 1].value)
          let ny

          if (ypx - previousNY < 10) {
            ny = previousNY + 15

                label: c.network,
                orientation: "leftRight",
                align: "middle"
              x={width - margin.right}
              dx={highlight.indexOf(c.network) !== -1 ? 20 : 5}
              ny={ny} //use ny to directly place the note in xy space if needed
          previousNY = ny || ypx

          return p
        }, [])

      const axisAnnotations = networkLines
        .filter(d => d.network === "HBO")[0]
        .line.map(d => (
            note={{ label: d.year, align: "middle", lineType: null }}
              y1: y(0),
              y2: y(d.value)

      const labels = networkLines
        .filter(d => highlight.indexOf(d.network) !== -1)
        .reduce((p, c) => {
          p = p.concat(
            c.line.map(d => {
              return {
                network: c.network,
                year: d.year,
                value: d.value
          return p
        }, [])

      const badgeAnnotations = labels.map(d => {
        return (
            key={d.year + d.network}
              text: d.value,
              radius: 12

      return (
        <div style={{ position: "relative" }}>
          <svg width={960} height={500} id="emmys">
            <g className="lineChart">
                className="basline axis"
          <div className="title">
            <b style={{ color: "#d32f2f" }}>Netflix</b> Challenges <b>HBO</b> at
            the 2017 Emmys

    ReactDOM.render(<LineChart />, document.getElementById("main"))

🕑 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 ..................