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

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

              
                <head>
  <meta charset="UTF-8">
  <title></title>
  <script src="https://cdn.plot.ly/plotly-latest.min.js">
  </script>
</head>
<body>
<div id="graphDiv"></div>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                var gd = document.getElementById('graphDiv');

var list = [
  {name: "Afghanistan", value: 31822848},
  {name: "Albania", value: 3020209},
  {name: "Algeria", value: 38813722},
  {name: "Andorra", value: 85458},
  {name: "Angola", value: 19088106},
  {name: "Antigua and Barbuda", value: 91295},
  {name: "Argentina", value: 43024374},
  {name: "Armenia", value: 3060631},
  {name: "Australia", value: 22507617},
  {name: "Austria", value: 8223062},
  {name: "Azerbaijan", value: 9686210},
  {name: "Bahamas, value: The", value: 321834},
  {name: "Bahrain", value: 1314089},
  {name: "Bangladesh", value: 166280712},
  {name: "Barbados", value: 289680},
  {name: "Belarus", value: 9608058},
  {name: "Belgium", value: 10449361},
  {name: "Belize", value: 340844},
  {name: "Benin", value: 10160556},
  {name: "Bhutan", value: 733643},
  {name: "Bolivia", value: 10631486},
  {name: "Bosnia and Herzegovina", value: 3871643},
  {name: "Botswana", value: 2155784},
  {name: "Brazil", value: 202656788},
  {name: "Brunei", value: 422675},
  {name: "Bulgaria", value: 6924716},
  {name: "Burkina Faso", value: 18365123},
  {name: "Burundi", value: 10395931},
  {name: "Cabo Verde", value: 538535},
  {name: "Cambodia", value: 15458332},
  {name: "Cameroon", value: 23130708},
  {name: "Canada", value: 34834841},
  {name: "Central African Republic", value: 5277959},
  {name: "Chad", value: 11412107},
  {name: "Chile", value: 17363894},
  {name: "China", value: 1355692576},
  {name: "Colombia", value: 46245297},
  {name: "Comoros", value: 766865},
  {name: "Congo Democratic Republic of the", value: 77433744},
  {name: "Congo Republic of the", value: 4662446},
  {name: "Costa Rica", value: 4755234},
  {name: "Cote d'Ivoire", value: 22848945},
  {name: "Croatia", value: 4470534},
  {name: "Cuba", value: 11047251},
  {name: "Cyprus", value: 1172458},
  {name: "Czech Republic", value: 10627448},
  {name: "Denmark", value: 5569077},
  {name: "Djibouti", value: 810179},
  {name: "Dominica", value: 73449},
  {name: "Dominican Republic", value: 10349741},
  {name: "Ecuador", value: 15654411},
  {name: "Egypt", value: 86895099},
  {name: "El Salvador", value: 6125512},
  {name: "Equatorial Guinea", value: 722254},
  {name: "Eritrea", value: 6380803},
  {name: "Estonia", value: 1257921},
  {name: "Ethiopia", value: 96633458},
  {name: "Fiji", value: 903207},
  {name: "Finland", value: 5268799},
  {name: "France", value: 66259012},
  {name: "Gabon", value: 1672597},
  {name: "Gambia, value: The", value: 1925527},
  {name: "Georgia", value: 4935880},
  {name: "Germany", value: 80996685},
  {name: "Ghana", value: 25758108},
  {name: "Greece", value: 10775557},
  {name: "Greenland", value: 57728},
  {name: "Grenada", value: 110152},
  {name: "Guatemala", value: 14647083},
  {name: "Guinea", value: 11474383},
  {name: "Guinea-Bissau", value: 1693398},
  {name: "Guyana", value: 735554},
  {name: "Haiti", value: 9996731},
  {name: "Honduras", value: 8598561},
  {name: "Hungary", value: 9919128},
  {name: "Iceland", value: 317351},
  {name: "India", value: 1236344631},
  {name: "Indonesia", value: 253609643},
  {name: "Iran", value: 80840713},
  {name: "Iraq", value: 32585692},
  {name: "Ireland", value: 4832765},
  {name: "Israel", value: 7821850},
  {name: "Italy", value: 61680122},
  {name: "Jamaica", value: 2930050},
  {name: "Japan", value: 127103388},
  {name: "Jordan", value: 7930491},
  {name: "Kazakhstan", value: 17948816},
  {name: "Kenya", value: 45010056},
  {name: "Kiribati", value: 104488},
  {name: "Korea, value: North", value: 24851627},
  {name: "Korea, value: South", value: 49039986},
  {name: "Kosovo", value: 1859203},
  {name: "Kuwait", value: 2742711},
  {name: "Kyrgyzstan", value: 5604212},
  {name: "Laos", value: 6803699},
  {name: "Latvia", value: 2165165},
  {name: "Lebanon", value: 5882562},
  {name: "Lesotho", value: 1942008},
  {name: "Liberia", value: 4092310},
  {name: "Libya", value: 6244174},
  {name: "Liechtenstein", value: 37313},
  {name: "Lithuania", value: 3505738},
  {name: "Luxembourg", value: 520672},
  {name: "Macedonia", value: 2091719},
  {name: "Madagascar", value: 23201926},
  {name: "Malawi", value: 17377468},
  {name: "Malaysia", value: 30073353},
  {name: "Maldives", value: 393595},
  {name: "Mali", value: 16455903},
  {name: "Malta", value: 412655},
  {name: "Marshall Islands", value: 70983},
  {name: "Mauritania", value: 3516806},
  {name: "Mauritius", value: 1331155},
  {name: "Mexico", value: 120286655},
  {name: "Micronesia Federated States of", value: 105681},
  {name: "Moldova", value: 3583288},
  {name: "Monaco", value: 30508},
  {name: "Mongolia", value: 2953190},
  {name: "Montenegro", value: 650036},
  {name: "Morocco", value: 32987206},
  {name: "Mozambique", value: 24692144},
  {name: "Burma", value: 55746253},
  {name: "Namibia", value: 2198406},
  {name: "Nauru", value: 9488},
  {name: "Nepal", value: 30986975},
  {name: "Netherlands", value: 16877351},
  {name: "New Zealand", value: 4401916},
  {name: "Nicaragua", value: 5848641},
  {name: "Niger", value: 17466172},
  {name: "Nigeria", value: 177155754},
  {name: "Norway", value: 5147792},
  {name: "Oman", value: 3219775},
  {name: "Pakistan", value: 196174380},
  {name: "Palau", value: 21186},
  {name: "Panama", value: 3608431},
  {name: "Papua New Guinea", value: 6552730},
  {name: "Paraguay", value: 6703860},
  {name: "Peru", value: 30147935},
  {name: "Philippines", value: 107668231},
  {name: "Poland", value: 38346279},
  {name: "Portugal", value: 10813834},
  {name: "Qatar", value: 2123160},
  {name: "Romania", value: 21729871},
  {name: "Russia", value: 142470272},
  {name: "Rwanda", value: 12337138},
  {name: "Saint Kitts and Nevis", value: 51538},
  {name: "Saint Lucia", value: 163362},
  {name: "Saint Vincent and the Grenadines", value: 102918},
  {name: "Samoa", value: 196628},
  {name: "San Marino", value: 32742},
  {name: "Sao Tome and Principe", value: 190428},
  {name: "Saudi Arabia", value: 27345986},
  {name: "Senegal", value: 13635927},
  {name: "Serbia", value: 7209764},
  {name: "Seychelles", value: 91650},
  {name: "Sierra Leone", value: 5743725},
  {name: "Singapore", value: 5567301},
  {name: "Slovakia", value: 5443583},
  {name: "Slovenia", value: 1988292},
  {name: "Solomon Islands", value: 609883},
  {name: "Somalia", value: 10428043},
  {name: "South Africa", value: 48375645},
  {name: "South Sudan", value: 11562695},
  {name: "Spain", value: 47737941},
  {name: "Sri Lanka", value: 21866445},
  {name: "Sudan", value: 35482233},
  {name: "Suriname", value: 573311},
  {name: "Swaziland", value: 1419623},
  {name: "Sweden", value: 9723809},
  {name: "Switzerland", value: 8061516},
  {name: "Syria", value: 17951639},
  {name: "Taiwan", value: 23359928},
  {name: "Tajikistan", value: 8051512},
  {name: "Tanzania", value: 49639138},
  {name: "Thailand", value: 67741401},
  {name: "Timor-Leste", value: 1201542},
  {name: "Togo", value: 7351374},
  {name: "Tonga", value: 106440},
  {name: "Trinidad and Tobago", value: 1223916},
  {name: "Tunisia", value: 10937521},
  {name: "Turkey", value: 81619392},
  {name: "Turkmenistan", value: 5171943},
  {name: "Tuvalu", value: 10782},
  {name: "Uganda", value: 35918915},
  {name: "Ukraine", value: 44291413},
  {name: "United Arab Emirates", value: 5628805},
  {name: "United Kingdom", value: 63742977},
  {name: "United States", value: 318892103},
  {name: "Uruguay", value: 3332972},
  {name: "Uzbekistan", value: 28929716},
  {name: "Vanuatu", value: 266937},
  {name: "Venezuela", value: 28868486},
  {name: "Vietnam", value: 93421835},
  {name: "Western Sahara", value: 554795},
  {name: "Yemen", value: 26052966},
  {name: "Zambia", value: 14638505},
  {name: "Zimbabwe", value: 13771721}
];

list.sort(function(a, b) {
  return ((a.value > b.value) ? -1 : ((a.name === b.name) ? 0 : 1));
});

var nColumns = 4;

var data = [];

var i;
for(i = 0; i < nColumns; i++) {
  data[i] = {
    type: 'bar',
    orientation: 'h',
    x: [],
    y: [],
    xaxis: 'x' + String(i + 1),
    yaxis: 'y' + String(i + 1),
    texttemplate: "%{x:.3s}",
    textposition: 'outside',
    marker: {
      color: 'green'
    }
  };
}

var maxValue = -Infinity;
for(i = 0; i < list.length; i++) {
  maxValue = Math.max(
    maxValue, 
    list[i].value
  );

  var n = Math.floor(i / list.length * nColumns);
  data[n].x.push(list[i].value);
  data[n].y.push(list[i].name);
}

var layout = {
  "title": {
    "text": "World population by country"
  },
  "showlegend": false,
  "width": 1200,
  "height": 1200,
  "grid": {
    "rows": 1, 
    "columns": nColumns, 
    "pattern": "independent"
  }
};

for(i = 0; i < nColumns; i++) {
  layout['xaxis' + String(i + 1)] = {
    range: [
      0, 
      maxValue * 1.2 // leave space for outside text
    ]
  };  
  layout['yaxis' + String(i + 1)] = {
    autorange: 'reversed'
  }
}

Plotly.newPlot(gd, {
  "data": data,
  "layout": layout
});
              
            
!
999px

Console