Responsive / Fluid Layouts in JavaScript
How to create figures with responsive/fluid layouts in JavaScript.
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
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 );