【问题标题】:Disable PDF and SVG download options in Highcharts在 Highcharts 中禁用 PDF 和 SVG 下载选项
【发布时间】:2014-10-03 16:05:05
【问题描述】:

我在我的网络应用程序中使用带有 exporting.js 的 Highcharts v4.0.3,我希望能够为最终用户提供以下下载选项:

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

但是,标准选项是:

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

我怎样才能自定义它以便它只为用户提供 JPG 和 PNG 选项?

【问题讨论】:

  • 只是出于好奇,他们是否可以将其导出为 PDF 或打印有什么关系?当然,他们可以打印他们保存的 JPG 或 PNG,或者将它们转换为 PDF。

标签: highcharts


【解决方案1】:

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

您需要将其设置为仅包含这样的 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();
    }
}]

【讨论】:

    【解决方案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';
        });
    }
    

    【讨论】:

      【解决方案3】:

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

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

      示例:click here
      参考:click here

      【讨论】:

        猜你喜欢
        • 2016-08-08
        • 1970-01-01
        • 1970-01-01
        • 2012-07-18
        • 1970-01-01
        • 2018-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多