Disable PDF and SVG download options in Highcharts

I am using Highcharts v4.0.3 with exporting.js in my web application and I want to be able to provide end users with the following download options:

  • Download chart as jpg
  • Download chart as PNG

However, the standard parameters are:

  • Print chart
  • Download chart as jpg
  • Download chart as PNG
  • Download chart in PDF
  • Download SVG Vector Graphics Chart

How can I configure it so that it simply provides JPG and PNG options for the user?

+6
source share
2 answers

You can manually set exporting.buttons.contextButton.menuItems ( API ) to contain any buttons you want. You want to set only JPG and PNG for it, for example:

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

Like in this JSFiddle demo .

Default:

 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' }); } }] 
+20
source

You can remove unnecessary parameters as follows:

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

Source: https://habr.com/ru/post/973623/


All Articles