highcharts在导出时如何自定义图表的表头

来源:互联网 发布:淘宝助理 二次验证 编辑:程序博客网 时间:2024/05/22 16:48

今天一天都在搞客户提出的需求,有这样一个需求说的是在导出图表的时候可以让客户自己去输入表头。因为我使用的是highcharts控件,所以自然而然的区api里查,后来查来半天并经过和同事的讨论把问题解决了。

代码如下:            

exporting: {
                buttons: {
                    contextButton: {
                        menuItems: [
                    {
                        text: '打印图表',
                        onclick: function () {
                            var headstr = prompt("请输入表头名称", "");
                            if (headstr) {
                                $('#container').highcharts().setTitle({ text: headstr });
                                this.print();
                            }
                        }
                    }, {
                        text: '导出png图片',
                        onclick: function () {
                            var headstr = prompt("请输入表头名称", "");
                            if (headstr) {
                                $('#container').highcharts().setTitle({ text: headstr });
                                this.exportChart({
                                    type: 'image/png'
                                });
                            }
                        }
                    }, {
                        text: '导出jpeg图片',
                        onclick: function () {
                            var headstr = prompt("请输入表头名称", "");
                            if (headstr) {
                                $('#container').highcharts().setTitle({ text: headstr });
                                this.exportChart({
                                    type: 'image/jpeg'
                                });
                            }
                        }
                    },
                    {
                        text: '导出pdf文档',
                        onclick: function () {
                            var headstr = prompt("请输入表头名称", "");
                            if (headstr) {
                                $('#container').highcharts().setTitle({ text: headstr });
                                this.exportChart({
                                    type: 'application/pdf'
                                });
                            }
                        }
                    },
                 {
                     text: '导出svg矢量图',
                     onclick: function () {
                         var headstr = prompt("请输入表头名称", "");
                         if (headstr) {
                             $('#container').highcharts().setTitle({ text: headstr });
                             this.exportChart({
                                 type: 'image/svg+xml'
                             });
                         }
                     }
                 }
                  ]
                    }
                }
            }

1 0
原创粉丝点击