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

              
                
<!-- 
  default bar height 4(em)
  optional:min,max
 -->
<div class="chart-container">
<canvas class="chart-space"
        data-title="Handbrake H.264 GPU Transcode"
        data-min="0"
        data-max="200"
        data-value-caption="FPS"
        data-values='{"Macbook Pro 2021 M1 Pro(GPU:16Core) ":164.83,"Macbook Pro 2020 M1":100.21,"Macbook Pro 2020 Intel Iris Plus":68.5,"Windows Desktop Intel Core-i5 10400 QSV":116.8}'></canvas>
</div>

<div class="chart-container">
<canvas class="chart-space"
        data-bar-height="8"
        data-title="Handbrake H.264 CPU Transcode"
        data-min="0"
        data-max="200"
        data-value-caption="FPS"
        data-values='{"Macbook Pro 2021 M1 Pro(CPU:10Core) ":72.42,"Macbook Pro 2020 M1":42.94,"Macbook Pro 2020 Intel Iris Plus":32.11,"Windows Desktop Intel Core-i5 10400(6Core/12Threads)":47.6}'></canvas>
</div>
              
            
!

CSS

              
                .chart-container{
  position:relative;
  width:100%;
}
              
            
!

JS

              
                (function () {
  // Chart.js Config
  const config = {
    type: "bar",
    data: {},
    options: {
      indexAxis: "y",
      maintainAspectRatio: false,
      plugins: {
        title: {
          display: true,
          font:{
            size:16
          },
          text: ""
        }
      },
      scales:{
        xAxis:{}
      }
    }
  };
  const data = {
    labels: [],
    datasets: [
      {
        axis: "y",
        data: [],
        fill: false,
        backgroundColor: [
          "rgba(255, 99, 132, 0.2)",
          "rgba(255, 159, 64, 0.2)",
          "rgba(255, 205, 86, 0.2)",
          "rgba(75, 192, 192, 0.2)",
          "rgba(54, 162, 235, 0.2)",
          "rgba(153, 102, 255, 0.2)",
          "rgba(201, 203, 207, 0.2)"
        ],
        borderColor: [
          "rgba(255, 99, 132, 0.2)",
          "rgba(255, 159, 64, 0.2)",
          "rgba(255, 205, 86, 0.2)",
          "rgba(75, 192, 192, 0.2)",
          "rgba(54, 162, 235, 0.2)",
          "rgba(153, 102, 255, 0.2)",
          "rgba(201, 203, 207, 0.2)"
        ],
        borderWidth: 1
      }
    ]
  };

  // build Charts
  var charts = document.getElementsByClassName("chart-space");
  for (var i = 0, max = charts.length; i < max; i += 1) {
    var chartEl = charts[i];
    var raw = JSON.parse(chartEl.dataset.values);
    var parent = chartEl.parentElement;
    var title = chartEl.dataset.title;
    var valueCaption = chartEl.dataset.valueCaption;
    var barHeightEm =
      typeof chartEl.dataset.barHeight === "undefined"
        ? 4
        : parseInt(chartEl.dataset.barHeight, 10);
    var __labels = [];
    var __data = [];

    var count = 0;
    for (key in raw) {
      __labels.push(key);
      __data.push(raw[key]);
      count++;
    }

    var _config = JSON.parse(JSON.stringify(config));
    var _data = JSON.parse(JSON.stringify(data));

    parent.style.height = barHeightEm * count + "em";

    _data.labels = __labels;
    _data.datasets[0].data = __data;
    _data.datasets[0].label = valueCaption;
    _config.data = _data;
    _config.options.plugins.title.text = title;
     if(typeof chartEl.dataset.min !== "undefined"){
     _config.options.scales.xAxis['min'] = parseInt(chartEl.dataset.min, 10);
   }
    if(typeof chartEl.dataset.max !== "undefined"){
     _config.options.scales.xAxis['max']= parseInt(chartEl.dataset.max, 10);
   }
    const myChart = new Chart(chartEl, _config);
  }
})();

              
            
!
999px

Console