Highcharts:如何获取图表上的默认导出选项?

时间:2014-09-17 23:20:15

标签: highcharts

我在项目中使用Highcharts。我使用以下内容隐藏图表导出选项的默认下拉列表:

$('#mycontainer").highcharts({
   ...
   chart: {
      type: 'column'
   },
   exporting: {
     enabled: false
   }
   ..
});

但是,我确实需要这些导出选项,我需要将它们与其他东西一起放在我自己的菜单中。如果我是对的,单个图表上的默认导出选项基本上是在客户端Javascript驱动的,与服务器无关。

如何重建这些导出选项并将它们放在javascript中?

更新

exports.js已包含在我的页面中,但我想禁用它生成的默认导出下拉列表,并将默认下拉导出选项移动到我自己的菜单中。我需要知道默认下拉选项链接或javascript是什么,以便我可以使我的菜单工作方式与默认导出下拉列表相同。

谢谢和问候。

1 个答案:

答案 0 :(得分:8)

默认导出选项(直接来自exporting.src.js):

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'
        });
    }
}
// Enable this block to add "View SVG" to the dropdown menu
/*
,{

    text: 'View SVG',
    onclick: function () {
        var svg = this.getSVG()
            .replace(/</g, '\n&lt;')
            .replace(/>/g, '&gt;');

        doc.body.innerHTML = '<pre>' + svg + '</pre>';
    }
} // */
]

此处this指的是图表本身,因此您可以将其替换为chart变量。

例如使用JPEG导出:

var chart = $('#container').highcharts();
chart.exportChart({
    type: 'image/jpeg'
});

或者查看this JSFiddle demonstration

相关问题