1

如何在鼠标悬停时在饼图上调用鼠标单击事件?我尝试了一些东西,但它的点击并不像我需要的那么顺利。这是代码示例:

   plotOptions: {
        pie: {
            innerSize: '50%',
            size: 100,
            cursor: 'pointer',
            dataLabels: false
        },
        series: {
            allowPointSelect: true,
            type: 'pie',
            name: 'Coordinates',
            point: {
                events: {
                    mouseOver: function (e) {
                      pieChart.tooltip.hide();
                        var serie = this.series.data[this.x];
                        var waitBeforeSelect = setTimeout(function () {
                            clearTimeout(waitBeforeSelect);
                            serie.select();
                            serie.series.show();
                            pieChart.tooltip.refresh(serie);
                        }, 500);

                        var serieName = serie.name;
                        var textToShow = serieName.substr(0, serieName.indexOf(';'));
                        $('#pieChartInfoText').children().text(textToShow);
                        $('#pieChartInfoText').children().css('color', serie.color);
                    },
                    mouseOut: function () {
                        pieChart.tooltip.hide();
                    }
                }
            }
        }
    },
4

2 回答 2

1

如果您真正想做的只是选择 mouseOver 上的点(我需要做的就是让我提出您的问题),您可以在 mouseOver 函数中调用 this.select(true) 。这没有超时延迟,但仍然可以添加。

于 2014-02-06T17:50:19.870 回答
0

谢谢你,伊戈尔!

是的,它对我帮助很大,但它也有一些缺点:如果你将鼠标多次移到图表上,它会反复来回移动,尤其是在Donut图表上可见。

这是代码片段:

series: {
            allowPointSelect: true,
            type: 'pie',
            name: 'Coordinates',
            point: {
                events: {
                    mouseOver: function (e) {
                        var serie = this.series.data[this.x];
                        if ((undefined == previousSerie) || (serie != previousSerie)) {
                            var point = this;

                            if (!point.selected) {
                                pieChart.tooltip.shared = true;

                                var timeout = setTimeout(function () {
                                    clearTimeout(timeout);
                                    point.firePointEvent('click');

                                    pieChart.tooltip.shared = false;
                                    pieChart.tooltip.refresh(point);
                                }, 700);
                            }

                            var serieName = serie.name;
                            var textToShow = serieName.substr(0, serieName.indexOf(';'));
                            $('#pieChartInfoText').children().text(textToShow);
                            $('#pieChartInfoText').children().css('color', serie.color);
                            previousSerie = serie;
                        } else {
                            previousSerie = serie;
                        }
                    },
                    mouseOut: function () {
                        //  pieChart.tooltip.hide();
                    }
                }
            }
        }
于 2012-10-05T13:48:11.567 回答