Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get remove of 'data table' option from High chart export

In my high chart , when I am including export option, it includes data table on context menu. If I am trying to include MenuItems , then I am loosing out the option to export to excel and CSV.

How do I just remove data table from Highchart export menu?

Highcharts.chart('container', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Browser market shares in January, 2018'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                style: {
                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                }
            }
        }
    },
    series: [{
        name: 'Brands',
        colorByPoint: true,
        data: [{
            name: 'Chrome',
            y: 61.41,
            sliced: true,
            selected: true
        }, {
            name: 'Internet Explorer',
            y: 11.84
        }, {
            name: 'Firefox',
            y: 10.85
        }, {
            name: 'Edge',
            y: 4.67
        }, {
            name: 'Safari',
            y: 4.18
        }, {
            name: 'Sogou Explorer',
            y: 1.64
        }, {
            name: 'Opera',
            y: 1.6
        }, {
            name: 'QQ',
            y: 1.2
        }, {
            name: 'Other',
            y: 2.61
        }]
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
like image 598
Simsons Avatar asked Jul 02 '18 07:07

Simsons


1 Answers

You can still use the menuItems with the extra values from export-data.js.

The complete list, with "data table", is this (JSFiddle):

["printChart",
"separator",
"downloadPNG",
"downloadJPEG",
"downloadPDF",
"downloadSVG",
"separator",
"downloadCSV",
"downloadXLS",
"viewData",
"openInCloud"]

Just remove "viewData" and any other values you do not need.

You could specifically remove it from the array, but this seems less ideal (JSFiddle):

Highcharts.chart('container', {
    // ...
}, function(chart) {
    var arr = chart.options.exporting.buttons.contextButton.menuItems;
    var index = arr.indexOf("viewData");
    if (index !== -1) arr.splice(index, 1);
});
like image 166
Halvor Holsten Strand Avatar answered Nov 15 '22 10:11

Halvor Holsten Strand