在Highcharts中禁用PDF和SVG下载选项

时间:2014-08-10 20:53:12

标签: highcharts

我在我的网络应用中使用了Highcharts v4.0.3和exports.js,我希望能够为最终用户提供以下下载选项:

  • 以JPG格式下载图表
  • 将图表下载为PNG

但是,标准选项是:

  • 打印图表
  • 以JPG格式下载图表
  • 将图表下载为PNG
  • 以PDF格式下载图表
  • 将图表下载为SVG矢量图形

如何自定义它以便只为用户提供JPG和PNG选项?

3 个答案:

答案 0 :(得分:26)

您可以手动设置exporting.buttons.contextButton.menuItemsAPI)以包含您想要的任何按钮。

您需要将其设置为仅包含JPG和PNG(仅限短格式textKey):

menuItems: ['downloadPNG','downloadJPEG']

或者更明确的函数调用(带有对象和onclick的长格式):

menuItems: [{
    textKey: 'downloadPNG',
    onclick: function () {
        this.exportChart();
    }
}, {
    textKey: 'downloadJPEG',
    onclick: function () {
        this.exportChart({
            type: 'image/jpeg'
        });
    }
}]

与这些JSFiddle演示一样:short formlong form

exporting.js的默认值为:

menuItems: [{
    textKey: 'printChart',
    onclick: function () {
        this.print();
    }
}, {
    separator: true
}, {
    textKey: 'downloadPNG',
    onclick: function () {
        this.exportChart();
    }
}, {
    textKey: 'downloadJPEG',
    onclick: function () {
        this.exportChart({
            type: 'image/jpeg'
        });
    }
}, {
    textKey: 'downloadPDF',
    onclick: function () {
        this.exportChart({
            type: 'application/pdf'
        });
    }
}, {
    textKey: 'downloadSVG',
    onclick: function () {
        this.exportChart({
            type: 'image/svg+xml'
        });
    }
}]

export-data.js的其他内容包括:

menuItems: [{
    textKey: 'downloadCSV',
    onclick: function () {
        this.downloadCSV();
    }
}, {
    textKey: 'downloadXLS',
    onclick: function () {
        this.downloadXLS();
    }
},{
    textKey: 'viewData',
    onclick: function () {
        this.viewData();
    }
},{
    textKey: 'openInCloud',
    onclick: function () {
        this.openInCloud();
    }
}]

答案 1 :(得分:2)

您可以通过以下方式删除不必要的选项:

if (Highcharts.getOptions().exporting) {
    let contextButton = Highcharts.getOptions().exporting.buttons.contextButton;
    contextButton.menuItems = contextButton.menuItems.filter((item) => {
        return item.textKey === 'downloadJPEG' || item.textKey === 'downloadPNG';
    });
}

答案 2 :(得分:0)

在chatOptions中,我们可以在高级图表菜单中写customize options,我们可以自定义下拉选项。
在图表选项中,我们可以这样写:

exporting: {
    buttons: {
      contextButton: {
        menuItems: ['downloadPNG', 'downloadJPEG', 'downloadPDF', 'downloadSVG'],
      },
    },
}

示例:click here
参考:click here