I'm using Plotly in Vue, and the plots are not properly rendering when I visit a new route. Only after hovering will the plot change to its proper size. When I change to another route with a different grid (for the same plot UUID), the plot seems to have some kind of wrong size, and it's overflowing the container. But if I hover on it, then it seems fine. Here is my code that I use for the plotting and relayout:
mounted() {
Plotly.plot(
this.$refs[this.chartCopy.uuid],
this.chartCopy.traces,
this.chartCopy.layout
);
this.$refs[this.chartCopy.uuid].on("plotly_hover", this.hover);
this.$refs[this.chartCopy.uuid].on("plotly_unhover", this.unhover);
},
watch: {
chart: {
handler: function () {
Plotly.react(
this.$refs[this.chartCopy.uuid],
this.chartCopy.traces,
this.chartCopy.layout
);
},
deep: true,
},
},
In the options and the layout, I set autosize
and responsive
to true
Is there a way to make the plot already the proper size (both height and width) without the need to hover over it?
Here is the reproduced example where this behavior can be clearly seen:
https://codesandbox.io/s/vuetify-with-plotly-20nev
Any kind of relayout sort of destroys the set layout of the plot, and only after hovering, it becomes correct.
One more thing is that I can't use Vue wrapper for Plotly (it has other issues), so I have to stick with using plotly.js
library only.