Pen Settings

HTML

CSS

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

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

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.

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

              
                <main>
  <section class="cols-2">
    <figure>
      <p>Gráfico radial</p>
      <h3>Comparativa global</h3>
      <canvas id="chart1"></canvas>
    </figure>
    <figure>
      <p>Gráfico de área polar</p>
      <h3>Montañas rusas por país</h3>
      <canvas id="chart2"></canvas>
    </figure>
  </section>

  <section class="cols-1">
    <figure>
      <p>Gráfico lineal</p>
      <h3>Construcciones por año</h3>
      <canvas id="chart6"></canvas>
    </figure>
  </section>

  <section class="cols-3">
    <figure>
      <p>Gráfico radial</p>
      <h3>Altura</h3>
      <canvas id="chart3"></canvas>
    </figure>
    <figure>
      <p>Gráfico de <em>donut</em></p>
      <h3>Modelos</h3>
      <canvas id="chart4"></canvas>
    </figure>
    <figure>
      <p>Gráfico de barras</p>
      <h3>Fuerza G</h3>
      <canvas id="chart5"></canvas>
    </figure>
  </section>

</main>
              
            
!

CSS

              
                body {
  background: #181f38;
  font-family: "Poppins", monospace;
  color: white;
  font-size: 0.7em;
  font-weight: 200;
  letter-spacing: 1px;
}

html {
  padding: 20px;
  font-weight: 300;
}

main {
  padding: 10px;
}

section {
  margin-bottom: 40px;
}


h2,
h3 {
  font-size: 1.4em;
  margin-bottom: 29px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 15px;
  font-weight: 200;
}

hr {
  border-color: white;
  margin-bottom: 50px;
}

figure {
  background-color: rgba(255, 255, 255, 0.05);
  padding: 10px 10px 30px;
}

figure p {
  margin-bottom: 7px;
  font-size: 0.8em;
}

canvas {
  width: 100%;
}

/* grid */

[class*="cols"] {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.cols-4 > * {
  width: 25%;
  margin: 10px;
}

.cols-3 > * {
  width: 33.33%;
  margin: 10px;
}

.cols-2 > * {
  width: 50%;
  margin: 10px;
}

.cols-1 > * {
  width: 100%;
  margin: 10px;
}

#chart6 {
  max-height: 300px;
}

              
            
!

JS

              
                // Some default styles
const styles = {
  color: {
    solids: [
      "rgba(116, 72, 194, 1)",
      "rgba(33, 192, 215, 1)",
      "rgba(217, 158, 43, 1)",
      "rgba(205, 58, 129, 1)",
      "rgba(156, 153, 204, 1)",
      "rgba(225, 78, 202, 1)"
    ],
    alphas: [
      "rgba(116, 72, 194, .2)",
      "rgba(33, 192, 215, .2)",
      "rgba(217, 158, 43, .2)",
      "rgba(205, 58, 129, .2)",
      "rgba(156, 153, 204, .2)",
      "rgba(225, 78, 202, .2)"
    ]
  }
};

// Some default configs
Chart.defaults.global.defaultFontColor = "#fff";
Chart.defaults.scale.gridLines.color = "#444";
Chart.defaults.global.elements.line.borderWidth = 1;
Chart.defaults.global.elements.rectangle.borderWidth = 1;
Chart.defaults.scale.ticks.display = false;

// API call
fetch("https://coasters-api.herokuapp.com/")
  .then((response) => response.json())
  .then((data) => printCharts(data));

function printCharts(allCoasters) {
  // Get some selected coasters
  const seletedNames = [
    "Formula Rossa",
    "Kingda Ka",
    "Red Force",
    "Millennium Force",
    "Shambhala",
    "Smiler",
    "Colossus",
    "Dragon Khan"
  ];
  const selectedCoasters = allCoasters.filter((eachCoaster) =>
    seletedNames.includes(eachCoaster.name)
  );

  countriesRadarChart(selectedCoasters, "chart1");
  compareRadialChart(allCoasters, "chart2");
  heightRadarChart(selectedCoasters, "chart3");
  modelDoughnutChart(allCoasters, "chart4");
  GForceBarsChart(allCoasters, "chart5");
  yearsBarChart(allCoasters, "chart6");
}

function countriesRadarChart(coasters, id) {
  const data = {
    labels: coasters.map((eachCoaster) => eachCoaster.name),
    datasets: [
      {
        label: "Altura",
        data: coasters.map((eachCoaster) => eachCoaster.height),
        borderColor: styles.color.solids[0],
        backgroundColor: styles.color.alphas[0]
      },
      {
        label: "Longitud",
        data: coasters.map((eachCoaster) => eachCoaster.length),
        borderColor: styles.color.solids[1],
        backgroundColor: styles.color.alphas[1],
        hidden: true
      },
      {
        label: "Inversiones",
        data: coasters.map((eachCoaster) => eachCoaster.inversions),
        borderColor: styles.color.solids[2],
        backgroundColor: styles.color.alphas[2]
      },
      {
        label: "Velocidad",
        data: coasters.map((eachCoaster) => eachCoaster.speed),
        borderColor: styles.color.solids[3],
        backgroundColor: styles.color.alphas[3]
      },
      {
        label: "Fuerza G",
        data: coasters.map((eachCoaster) => eachCoaster.gForce),
        borderColor: styles.color.solids[4],
        backgroundColor: styles.color.alphas[4]
      }
    ]
  };

  const options = {
    legend: {
      position: "right"
    }
  };

  new Chart(id, { type: "radar", data, options });
}

function compareRadialChart(coasters, id) {
  const data = {
    labels: ["Estados Unidos", "Reino Unido", "España", "Japón", "China"],
    datasets: [
      {
        data: [
          coasters.filter(
            (eachCoaster) => eachCoaster.country === "United States"
          ).length,
          coasters.filter(
            (eachCoaster) => eachCoaster.country === "United Kingdom"
          ).length,
          coasters.filter((eachCoaster) => eachCoaster.country === "Spain")
            .length,
          coasters.filter((eachCoaster) => eachCoaster.country === "Japan")
            .length,
          coasters.filter((eachCoaster) => eachCoaster.country === "China")
            .length
        ],
        borderColor: styles.color.solids.map((color) => color),
        backgroundColor: styles.color.alphas.map((color) => color)
      }
    ]
  };

  const options = {
    legend: {
      position: "right"
    }
  };

  new Chart(id, { type: "polarArea", data, options });
}

function heightRadarChart(coasters, id) {
  const data = {
    labels: coasters.map((eachCoaster) => eachCoaster.name),
    datasets: [
      {
        label: "Altura",
        data: coasters.map((eachCoaster) => eachCoaster.height),
        borderColor: styles.color.solids[0],
        backgroundColor: styles.color.alphas[0]
      }
    ]
  };

  const options = {
    legend: {
      display: false
    }
  };

  new Chart(id, { type: "radar", data, options });
}

function modelDoughnutChart(coasters, id) {
  const data = {
    labels: [
      "Propulsada",
      "Hyper montaña",
      "Giga montaña",
      "Multi inversión",
      "Sentado"
    ],
    datasets: [
      {
        label: "Longitud",
        data: [
          coasters.filter(
            (eachCoaster) => eachCoaster.model === "Accelerator Coaster"
          ).length,
          coasters.filter(
            (eachCoaster) => eachCoaster.model === 'Hyper Coaster"'
          ).length,
          coasters.filter((eachCoaster) => eachCoaster.model === "Giga Coaster")
            .length,
          coasters.filter(
            (eachCoaster) => eachCoaster.model === "Multi Inversion Coaster"
          ).length,
          coasters.filter(
            (eachCoaster) => eachCoaster.model === "Sitting Coaster"
          ).length
        ],
        borderColor: styles.color.solids.map((eachColor) => eachColor),
        backgroundColor: styles.color.alphas.map((eachColor) => eachColor)
      }
    ]
  };

  const options = {
    legend: {
      position: "right"
    }
  };

  new Chart(id, { type: "doughnut", data, options });
}

function speedRadarChart(coasters, id) {
  const data = {
    labels: coasters.map((eachCoaster) => eachCoaster.name),
    datasets: [
      {
        label: "Velocidad",
        data: coasters.map((eachCoaster) => eachCoaster.speed),
        borderColor: styles.color.solids[2],
        backgroundColor: styles.color.alphas[2]
      }
    ]
  };

  const options = {
    legend: {
      display: false
    }
  };

  new Chart(id, { type: "radar", data, options });
}

function yearsBarChart(coasters, id) {
  const data = {
    labels: [
      "1995-1997",
      "1998-2000",
      "2001-2003",
      "2004-2006",
      "2007-2009",
      "2010-2012",
      "2013-2015",
      "2016-2018",
      "2019-2021"
    ],
    datasets: [
      {
        label: "Montañas creadas",
        borderColor: styles.color.solids[5],
        data: [
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 1995 && eachCoaster.year <= 1997
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 1998 && eachCoaster.year <= 2000
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2001 && eachCoaster.year <= 2003
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2004 && eachCoaster.year <= 2006
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2007 && eachCoaster.year <= 2009
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2010 && eachCoaster.year <= 2012
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2013 && eachCoaster.year <= 2015
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2016 && eachCoaster.year <= 2018
          ).length,
          coasters.filter(
            (eachCoaster) =>
              eachCoaster.year >= 2019 && eachCoaster.year <= 2021
          ).length
        ]
      }
    ]
  };

  const options = {
    scaleFontColor: "#FFFFFF",
    maintainAspectRatio: false,
    legend: {
      display: false
    },
    scales: {
      yAxes: [
        {
          gridLines: {
            display: false
          },
          ticks: {
            display: true
          }
        }
      ],
      xAxes: [
        {
          ticks: {
            display: true
          }
        }
      ]
    }
  };

  new Chart(id, { type: "line", data, options });
}

function GForceBarsChart(coasters, id) {
  const selectedCoasters = coasters
    .filter((coaster) => coaster.gForce)
    .splice(1);

  const data = {
    labels: selectedCoasters.map((eachCoaster) => eachCoaster.name),
    datasets: [
      {
        data: selectedCoasters.map((eachCoaster) => eachCoaster.gForce),
        backgroundColor: styles.color.alphas,
        borderColor: styles.color.solids
      }
    ]
  };

  const options = {
    scaleFontColor: "#FFFFFF",
    scales: {
      yAxes: [
        {
          gridLines: {
            display: false
          },
          ticks: {
            display: true
          }
        }
      ]
    },
    legend: {
      display: false
    }
  };

  new Chart(id, { type: "bar", data, options });
}

              
            
!
999px

Console