如何在新标签中打开高级图表的信用URL

时间:2013-05-29 09:43:41

标签: javascript highcharts

如何在新标签中打开highcharts信用url

credits: {
    enabled: true,
    text: 'text',
    href: 'url'
},

3 个答案:

答案 0 :(得分:12)

在图表加载事件中绘制图表后,您可以重新定义信用点击处理程序:

    chart: {
        events:{
            load: function() {
                this.credits.element.onclick = function() {
                    window.open(
                      'http://www.example.com',
                      '_blank'
                    );
                 }
            }
        }                
    },

小提琴here

答案 1 :(得分:3)

<强> http://jsfiddle.net/ptasdfmk/

// Plugin to add support for credits.target in Highcharts.
Highcharts.wrap(Highcharts.Chart.prototype, 'showCredits', function (proceed, credits) {
    proceed.call(this, credits);

    if (credits.enabled && this.credits) {
        this.credits.element.onclick = function () {

            // dynamically create an anchor element and click it
            // use the settings defined in highcharts (credits.target)

            var link = document.createElement('a');
            link.href = credits.href;
            link.target = credits.target;
            link.click();

        }
    }
});

$('#container').highcharts({

    credits: {
        enabled: true,
        text: 'CREDITS',
        href: 'http://example.com',
        target: '_blank'
    },  

});

使用Highcharts配置(带目标的信用部分),当您单击“CREDITS”时,即时创建一个新的链接元素并单击。链式事件。这允许重用代码并根据配置执行操作。

答案 2 :(得分:3)

这是适合我的解决方案。

credits: {
    enabled: true,
    text: 'text',
    href: 'javascript:window.open("http://www.example.com/", "_blank")'
},