cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

    <script src="https://aframe.io/releases/0.7.0/aframe.min.js"></script>
       AFRAME.registerComponent('barchart', {
          schema: {
            json: {
              default: {
                key: ['A', 'B', 'C', 'D', 'E'],
                value: [19, 80, 30, 15, 55]
          init: function () {
            var self = this;
            if (typeof this.data.json === 'string') {
                .then(function(response) {
                  return response.json();
                }).then(function(parsedJson) {
                }).catch(function(ex) {
                  console.log('parsing failed', ex)

          generate: function (parsedJson) {
            var json = parsedJson || this.data.json;
            var el = this.el;
            // default alpha for bars
            var alpha = 0.6;
            var data = json.map(function(obj) {return obj.value;});
            var dataText = json.map(function(obj) {return obj.key;});
            // Scale the height of our bars using d3's linear scale
            var hscale = d3.scaleLinear()
              .domain([0, d3.max(data)])
              .range([0, 3]);
            var color = d3.scaleLinear().domain([0, d3.max(data)])
              .interpolate(d3.interpolateHcl).range(['#ffb3ba', '#bae1ff']);

            // Select the current enity object just like an svg
            var currentEntity = d3.select(el);

            // we use d3's enter/update/exit pattern to draw and bind our dom elements
            var bars = currentEntity.selectAll('a-box.bar').data(data);
            // we set attributes on our cubes to determine how they are rendered
            bars.enter().append('a-box').classed('bar', true)
              .attr('position',function (d, i) {
              const x =  i * 0.8 - (data.length / 2);
              const y = hscale(d)/2;
              const z = -3
              return x + " " + y + " " + z   
              .attr('width', function(d) { return 0.5; })
              .attr('depth', function(d) { return 0.5; })
              .attr('height', function(d) { return hscale(d); })
              .attr('opacity', alpha)
              .attr('color', function(d) { return color(d); })
              .on("mouseenter", function(d,i) {
                  .attr('opacity', 0.9);

                  .attr('color', color(d))
                  .attr('align', 'center')
                  .attr('position', `0 ${(hscale(d) / 2 + 0.5)} 0`)
                  .attr('scale', '1 1 1')
                  .attr('value', `${dataText[i]}, ${d}`);
              .on("mouseleave", function(d,i) {
                  .attr('opacity', alpha);

  <body style="background: #111;">
        <img id="groundTexture" src="https://cdn.aframe.io/a-painter/images/floor.jpg" crossorigin>
      <a-entity position="-1 2 0" rotation="0 0 0">
        <a-entity camera look-controls wasd-controls>
          <a-entity cursor="fuse: true; fuseTimeout: 500"
                    position="0 0 -2"
                    geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.027"
                    material="color: black; shader: flat">
      <a-entity text="font: mozillavr; value: 104 Taiwan Demographics (age, population) ; color: #DADADA; width: 6"
                  position="-2 4 -3"></a-entity>
      <a-entity barchart="json: https://cdn.rawgit.com/ArvinH/f47671a9ff33b6719b043945d36054ac/raw/09a6ea23ee40d4a83205eef6d4fd4e5efa072c2b/104life.json"></a-entity>
      <a-cylinder id="ground" src="#groundTexture" radius="32" height="0.1"></a-cylinder>
🕑 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 ..................