【问题标题】:Highcharts: how to get the default export options on a chart?Highcharts:如何在图表上获取默认导出选项?
【发布时间】:2014-09-17 23:20:14
【问题描述】:

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

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

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

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

更新

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

感谢和问候。

【问题讨论】:

  • 您在寻找
  • Swetha,我知道这个脚本。它已经包含在我的页面中。但我不想要 exporting.js 生成的默认导出下拉列表。我希望将默认导出下拉选项添加到我自己的菜单中。谢谢!

标签: highcharts


【解决方案1】:

默认导出选项是(直接来自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

【讨论】:

  • Ondkloss,非常感谢您帮助我。我试过 chart.exportChart({ type: 'image/jpeg' });直接在 var chart = $('#container').highcharts(); 之后我收到 javascript 错误:chartObject.exportChart 不是函数
  • 我还使用 setTimeout 调用 exportChart 以确保图表对象已完全构建。 setTimeout(function(){ chart.exportChart({ type: 'image/jpeg' }); }, 3000);我仍然遇到同样的 javascript 错误。
  • 哦,是的,很好奇1。这仍然需要 exporting.js 包含,因此您只需禁用该按钮,就像您已经完成的那样。
  • Ondkloss,当我包含 exporting.js 并禁用按钮时,我收到了 javascript 错误。谢谢!
  • 有错误吗?你的意思是修好了?我还在答案中添加了一个 JSFiddle。希望您解决了您的问题。
猜你喜欢
  • 1970-01-01
  • 2021-03-08
  • 1970-01-01
  • 2021-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-19
相关资源
最近更新 更多