您的位置:首页 > 其它

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

2016-02-23 17:21 295 查看
今天一天都在搞客户提出的需求,有这样一个需求说的是在导出图表的时候可以让客户自己去输入表头。因为我使用的是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'

                             });

                         }

                     }

                 }

                  ]

                    }

                }

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  需求 api 控件 函数