首页 文章

如何在highCharts中添加自定义导出按钮?

提问于
浏览
1

我们在应用程序中使用highcharts,我想在打印和导出按钮旁边添加一个按钮 . 我确实在jsfiddle中有工作示例

var chart1;
        $(document).ready(function () {

            // Add Custom button to highchart
            chart1 = new Highcharts.Chart({
                chart: {
                    renderTo: 'container1',
                    shadow: true
                },
                title: { text: 'Sales' },
                xAxis: {
                    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
                },
                yAxis: { title: { text: '$'} },
                series: [{
                    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 
                           135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
                }],
                 exporting: {
                        buttons: {
                            'exportTo': {
                                _id: 'exportTo',
                                symbol: 'diamond',
                                x: -62,
                                symbolFill: '#B5C9DF',
                                hoverSymbolFill: '#779ABF',
                                onclick: function () {
                                    showDialog(this);
                                }
                            }
                        }
                    }

            });


 var showDialog = function (selectedChart) {

                var modal = $("#myModal").modal();
                $('#btnSaveImage').click(function () {
                    saveChartInNas(selectedChart);
                    modal.modal('hide');
                });
            };
        });

我们有很多图表,点击图表我想显示模态窗口并在保存按钮上执行一些处理 . 我想知道是否有可能 some kind of plugin or add on ? 而不是为所有不同页面中的所有图表创建模态和导出属性设置 . 如果是这样,有人可以告诉我如何实现这一点 .

我不想在所有页面中添加导出逻辑 .

谢谢

2 回答

  • 1

    我想你在问是否有办法将其设置为某种默认的,编辑每个图表定义的instad?

    您应该看看Highcharts.setOptions()http://api.highcharts.com/highcharts#Highcharts.setOptions()这允许您为所有图表设置默认值 .

  • 1
    exporting: {
                               filename: 'event-id-metadata-graph',
                                buttons: {
                                    contextButton: {
                                        menuItems: [{
                                            text: 'Download PDF',
                                            onclick: function () {
                                                this.exportChart({
                                                    type: 'application/pdf'
                                                });
                                            }
                                        }, {
                                            text: 'Print',
                                            onclick: function () {
                                                    alert('Launch Print Table function')
                                            },
                                            separator: false
                                        }]
                                    }
                                }
                            },
    

相关问题