如何从高图表导出中删除“数据表”选项

时间:2018-07-02 07:15:27

标签: javascript highcharts export export-to-excel

在我的高级图表中,当我包括导出选项时,它包括上下文菜单中的数据表。如果我尝试包含MenuItems,那么我就失去了导出到excel和CSV的选项。

如何从Highchart导出菜单中删除数据表?

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>

1 个答案:

答案 0 :(得分:6)

您仍然可以将menuItemsexport-data.js配合使用。

带有“数据表”的完整列表是(JSFiddle):

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

只需删除"viewData"和其他不需要的值即可。

您可以从数组中专门删除它,但这似乎不太理想(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);
});