Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我尝试打开一个新窗口时,google图表中的事件单击会阻止弹出窗口_Javascript_Jquery_Events_Google Visualization - Fatal编程技术网

Javascript 当我尝试打开一个新窗口时,google图表中的事件单击会阻止弹出窗口

Javascript 当我尝试打开一个新窗口时,google图表中的事件单击会阻止弹出窗口,javascript,jquery,events,google-visualization,Javascript,Jquery,Events,Google Visualization,当我试图打开一个新窗口时,谷歌图表上的事件点击会阻止弹出窗口 以下是我绘制图表的方式: printChart: function() { var self = this; google.load('visualization', '1', { 'packages': ['corechart'], "callback": function() { try {

当我试图打开一个新窗口时,谷歌图表上的事件点击会阻止弹出窗口

以下是我绘制图表的方式:

    printChart: function() {
        var self = this;

        google.load('visualization', '1', {
            'packages': ['corechart'],
            "callback": function() {
                try {
                    showLoading('widget');

                    var data = google.visualization.arrayToDataTable([]);
                    data.addColumn('string', 'Classification');                     
                    data.addColumn('number', $.t('columnVisits'));
                    data.addColumn('number', $.t('columnContacted'));
                    data.addColumn('number', $.t('columnUnattended'));
                    data.addColumn('number', '');
                    data.addColumn({ type: 'string', role: 'annotation' });


                    //We add all the elements to the graph
                    var dataClassified = self.getClassifiedFromConfig();

                    _.each(dataClassified, function(element) {
                        var inactive = (element.Inactive <= 0 && element.Visits <= 0 && element.ActivitiesPhoneCalls <= 0) ? 1 : element.Inactive,
                            assigned = element.Assigned > 0 ? element.Assigned : 1;

                        data.addRow([
                                    {
                                        v: element.IdClassification.toString(),
                                        f: element.Classification
                                    },
                                    element.Visits/assigned,
                                    element.ActivitiesPhoneCalls/assigned,
                                    inactive/assigned,
                                    0, //empty column for placing the Cycle as an annotation at the end of the stacked bars.
                                    element.Cycle + ' ' + $.t('days')
                        ]);
                    });

                    var options = {
                        isStacked: true,
                        hAxis: {
                            format: '#%',
                            minValue: 0,
                            maxValue: 1,
                            textStyle: {
                                color: '#404040',
                                fontName: 'Roboto',
                                fontSize: 14
                            }
                        },
                        vAxis: {
                            textStyle: {
                                color: '#404040',
                                fontName: 'Roboto',
                                fontSize: responsiveFontSize
                            }
                        },
                        bar: {
                            groupWidth: '75%'
                        },
                        annotations: {
                            alwaysOutside: true,
                            stemColor: 'none', // eliminate the tick for the annotation
                            textStyle: {
                                fontName: 'Roboto',
                                fontSize: 14,
                                bold: false,
                                italic: false,
                                color: '#404040'
                            }
                        },
                        series: {
                            3: {
                                visibleInLegend: false 
                            }
                        },
                        legend: {
                            position: 'top'
                        },
                        tooltip: {
                            trigger: 'none'
                        },
                        height: responsiveHeight,
                        width: '100%',
                        colors: ['#85ac1f', '#fccd3d', '#eaeaea'],
                        enableInteractivity: true
                    };

                    var chart = new google.visualization.BarChart(document.getElementById('portfolio-coverage-chart'));

                    google.visualization.events.addListener(chart, 'onmouseover', function(e){
                        self.mouseOverHandler(chart, data);
                    });

                    google.visualization.events.addListener(chart, 'select', function(e){
                        self.selectHandler(chart, data);
                    });

                    /*$('.portfolio-coverage-chart').on('click', function() {
                        self.selectHandler(chart, data);
                    });*/

                    chart.draw(data, options);
                } catch (e) {
                    console.log("error printChart " + e);
                } finally {
                    hideLoading('widget');
                }

            }
        });
    },
“selectHandler”功能:

    selectHandler: function(chart, data) {
        var self = this;
        var id = 5;
        var customView = "";
        var elementClick = chart.getSelection();

        if (elementClick.length > 0){
            var row = elementClick[0].row,
                column = elementClick[0].column;

            if (column === 1) {
                id = 5;
                customView = "customview.visitcompanies";
            } else if (column === 2) {
                id = 6;
                customView = "customview.contactcompanies";
            } else if (column === 3) {
                id = 7;
                customView = "customview.unattendedcompanies";
            } else {
                return;
            }

            //nulls out the selection so we can select it again
            chart.setSelection();

            var idClassification = parseInt(data.getValue(row, 0));
            var params = self.setParams(idClassification);

            doDrilldown(id, customView, "companies", params);
        }
    }
然后,“doDrillDown”方法尝试应用window.open函数打开一个新窗口:

// open entity page
var newTab = window.open(url, '_blank');
if (newTab) {
    newTab.focus();
} else {
    alert('Please allow popups for this website');
}
但是在打开新窗口之前,我的网站的弹出窗口会被阻止

如果我调用的不是google的事件处理程序,而是一个点击事件按预期工作(这里的问题是“chart.getSelection();”中的数据没有更新,并且我在最后一个事件之前完成了选择):


为什么会发生这种情况?

你能再多展示一下发生了什么吗?我认为这些东西是以某种形式的点击事件。如果是这样的话,通过查看单击事件设置,就可以找出Google图表事件单击干扰弹出代码的原因。@AndrewGray,几个月前我用更多信息编辑了我的问题。你知道发生了什么吗?你能再多展示一下吗?我认为这些东西是以某种形式的点击事件。如果是这样的话,通过查看单击事件设置,就可以找出Google图表事件单击干扰弹出代码的原因。@AndrewGray,几个月前我用更多信息编辑了我的问题。你知道发生了什么事吗?
// open entity page
var newTab = window.open(url, '_blank');
if (newTab) {
    newTab.focus();
} else {
    alert('Please allow popups for this website');
}
$('.portfolio-coverage-chart').on('click', function() {
                            self.selectHandler(chart, data);
                        });