如何从 Highchart 导出中删除“数据表”选项?

5

在我的highchart中,当我包含导出选项时,它会在上下文菜单中包括数据表。如果我尝试包含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个回答

14
你仍然可以使用来自export-data.js的额外值与menuItems。完整列表,包括“数据表”,在这里(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);
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接