0

I am using HighCharts. Now just by importing exporting.js file I get all the format for exporting like png, jpeg, PDF, SVG, CSV and EXCEL. What should I do to restrict some options? Like if I want only export to excel functionality how do I restrict other options?

Thanks in advance.

Half Blood Prince
  • 951
  • 2
  • 13
  • 25
  • See this http://www.highcharts.com/plugin-registry/single/37/highcharts-export-clientside and http://stackoverflow.com/questions/9685681/how-to-remove-button-from-highcharts – Satyaki Chatterjee Feb 22 '16 at 07:19

3 Answers3

2

You can get default options this way:

var options = Highcharts.getOptions().exporting.buttons.contextButton.menuItems;

Now, simply modify that array:

options.splice(4, 1); // remove PDF

And use in options:

exporting: {
  buttons: {
    contextButton: {
      menuItems: options
    }
  }
},

Demo: http://jsfiddle.net/pscjzhe4/283/

Paweł Fus
  • 44,795
  • 3
  • 61
  • 77
1

In your HTML:

<button type="button" class="btn btn-default" data-type="application/vnd.ms-excel">XLS</button>

You can use exportChartLocal:

 $('#exportExcel').click(function(){
      var chart = $('#example-1').highcharts();
      chart.exportChartLocal({ type: 'application/vnd.ms-excel' });
});

Check this FIDDLE

Dharman
  • 30,962
  • 25
  • 85
  • 135
IsraGab
  • 4,819
  • 3
  • 27
  • 46
  • Thanks @IsraGab for your answer. I have done this.The thing is I do not want all options for export. I only want 'Download to XLS'. How do I hide or restrict other options? – Half Blood Prince Feb 22 '16 at 09:47
  • I think you are not understanding my question. I do not want to show options like 'Download PNG image', ''Download JPEG image'' etc. I just want 'Download XLS' and no other options. How do I do that? – Half Blood Prince Feb 22 '16 at 11:47
  • Just don't display the options, I gave you a code and a fiddle. Can you see there "Download JPEG" etc... ?? – IsraGab Feb 22 '16 at 12:21
  • Oops! I was checking the chart context menu on top right corner. Yes, I can work with that button 'XLS'. Thanks. – Half Blood Prince Feb 22 '16 at 12:39
  • By the way is there any way to restrict options in that chart context menu? – Half Blood Prince Feb 22 '16 at 12:41
  • OK! now I understand what you were asking for :). Sorry, I didn't pay attention to this button. If I were you, I would hide it and customize another dropdown `navigation: { buttonOptions: { enabled: false } }, ` or customise it if you want – IsraGab Feb 22 '16 at 13:04
  • If you want to customize it and let only excel you can do `Highcharts.getOptions().exporting.buttons.contextButton.menuItems; options.splice(0, 7); ` – IsraGab Feb 22 '16 at 13:07
  • But if I were you I would prefere to do my own dropdown/button. If highcharts is changing the order in this menu your code won't be good – IsraGab Feb 22 '16 at 13:09
  • Yes this is exactly what I wanted. Thanks a lot! – Half Blood Prince Feb 22 '16 at 13:14
1
exporting: {
    buttons: {
          contextButton{
              menuItems:['printChart', 'downloadPNG', 'downloadCSV', 'downloadXLS']
          }
        }
      }

You can get more menu items from this link to suit your needs --> https://api.highcharts.com/highcharts/exporting.buttons.contextButton.menuItems

Deepak Agrawal
  • 121
  • 1
  • 4