Plotly JS method to dynamically use the full height/width of a div
P粉012875927
P粉012875927 2023-08-25 19:48:49
0
1
480

When the top button is clicked, the size of the container #myDiv changes. How can I make Plotly automatically occupy all available space in a container,without any noticeable delay?

There is some higher latency here:

var z = [], steps = [], i; for (i = 0; i < 500; i ) z.push(Array.from({length: 600}, () => Math.floor(Math.random() * 100))); for (i = 0; i < 100; i ) steps.push({ label: i, method: 'restyle', args: ['line.color', 'red']}); var data = [{z: z, colorscale: 'YlGnBu', type: 'heatmap'}]; var layout = {title: '', sliders: [{ pad: {t: 5}, len: 1, x: 0, currentvalue: {xanchor: 'right', prefix: 'i: ', font: {color: '#888', size: 20}}, steps: steps }]}; Plotly.newPlot('myDiv', data, layout); document.getElementById('button').onclick = () => { document.getElementById('myDiv').classList.toggle('size2'); Plotly.Plots.resize('myDiv'); }
#button { background-color: gray; } #myDiv { width: 500px; height: 300px; border: 2px solid black; } .size2 { width: 300px !important; height: 200px !important; }
 Click here to change size 
Hello world

P粉012875927
P粉012875927

reply all (1)
P粉046878197

To make Plotly automatically occupy all available space of the container, you can use the 'autosize' option in the layout object.

var layout = { title: '', autosize: true, sliders: [{ pad: {t: 5}, len: 1, x: 0, currentvalue: { xanchor: 'right', prefix: 'i: ', font: { color: '#888', size: 20 } }, steps: steps }] };
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!