Plotly.js自动缩放

Mat*_*e3o 5 javascript plotly

Plotly.js中是否有参数可自动调整轴以自动拟合绘制的数据?

场景:我在最近的30分钟内绘制温度(y轴)与时间(x轴)的关系图.

问题:页面加载时,图表不显示任何内容.我会修复轴,但x轴需要显示最新的30分钟并每分钟更新一次.但是,当我点击"自动缩放"或"重置轴"时,图表完全符合数据!

问题:我可以将图表设置为在页面加载时自动"自动缩放",而不是要求用户单击"自动缩放"吗?

在此处查看应用:https://vast-fortress-23871.herokuapp.com/

dam*_*amd 8

一个非常愚蠢的黑客是添加这个:

document.querySelector('[data-title="Autoscale"]').click()
Run Code Online (Sandbox Code Playgroud)

它将自动单击“自动缩放”按钮。更好的方法是找出按钮实际调用的函数并调用它。


小智 5

For me, this worked perfectly and simply (thanks to https://codepen.io/plotly/pen/KpLVzv):

// script comes before
var layout = {
  xaxis: {
    autorange: true,
    showgrid: false,
    zeroline: false,
    showline: false,
    etc.
    }
// script comes after
Run Code Online (Sandbox Code Playgroud)