Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Plotly.js modebar,下载为png,给png起个名字_Javascript_Plotly - Fatal编程技术网

Javascript Plotly.js modebar,下载为png,给png起个名字

Javascript Plotly.js modebar,下载为png,给png起个名字,javascript,plotly,Javascript,Plotly,我的网页上有一个Plotly,您可以通过单击模式栏中的图片图标将其作为png下载。但是,当我单击它时,它会以png的形式下载,并命名为new plot,我如何给它一个自定义名称 我当前的代码(var数据只是数据,所以请忽略它): 使用绘图。下载图像 将此添加到按钮回调的modebar设置中: Plotly.downloadImage({ filename: 'customNamedImage', format: 'png', //also can use 'jpeg', 'we

我的网页上有一个Plotly,您可以通过单击模式栏中的图片图标将其作为png下载。但是,当我单击它时,它会以png的形式下载,并命名为new plot,我如何给它一个自定义名称

我当前的代码(var数据只是数据,所以请忽略它):


使用绘图。下载图像

将此添加到按钮回调的modebar设置中:

Plotly.downloadImage({
    filename: 'customNamedImage',
    format: 'png', //also can use 'jpeg', 'webp', 'svg'
    height: 500,
    width: 500
});
编辑:

我运行了一个自定义示例,我想您会希望在modebar中自定义自己的下载按钮,如下所示:

Plotly.newPlot(gd, [{
  y: [1, 2, 1],
  line: { shape: 'spline' }
}], {
  title: 'custom modebar button',
  width: 400,
  height: 700
}, {
  showTips: false,
  displayModeBar: true,
  modeBarButtons: [[{
    name: 'custom download button',
    icon: Plotly.Icons.camera,
    click: function (gd) {
      Plotly.downloadImage(gd, {
        filename: 'your_custom_name',
        format: 'jpeg',
        width: gd._fullLayout.width,
        height: gd._fullLayout.height
      })
    }
  }, 'toImage'
  ], []]
})

在较新版本的Plotly(v1.38+)中,有一种更简单的方法可以实现这一点。在配置中使用
toImageButtonOptions
参数,如下所示:

Plotly.newPlot(graphDiv, data, layout, {
    toImageButtonOptions: {
        filename: 'image_filename',
        width: 800,
        height: 600,
        format: 'png'
    }
});

您可以省去不需要使用默认值的选项。

我需要在哪里添加这些选项?感谢
width:gd.\u fullLayout.width
。这非常有用!
Plotly.newPlot(graphDiv, data, layout, {
    toImageButtonOptions: {
        filename: 'image_filename',
        width: 800,
        height: 600,
        format: 'png'
    }
});