Responsive / Fluid Layouts in JavaScript

How to create figures with responsive/fluid layouts in JavaScript.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.

If you set the responsive attribute equal to true (using the config object), then your figures will be automatically resized when the browser window size changes. This is an especially useful feature for charts which are going to viewed on mobile devices!

var trace1 = {
  type: 'bar',
  x: [1, 2, 3, 4],
  y: [5, 10, 2, 8],
  marker: {
      color: '#C8A2C8',
      line: {
          width: 2.5
      }
  }
};

var data = [ trace1 ];

var layout = {
  title: {
    text: 'Responsive to window\'s size!'
  },
  font: {size: 18}
};

var config = {responsive: true}

Plotly.newPlot('myDiv', data, layout, config );
Click to copy
0.511.522.533.544.50246810
Responsive to window's size!