gpt4 book ai didi

javascript - highcharts 一次性选择多个点

转载 作者:行者123 更新时间:2023-12-02 15:30:49 24 4
gpt4 key购买 nike

我想在 Highcharts 中实现多点选择,我已经制作了这个示例来说明我的进度,但似乎我的代码选择事件被多次调用,具体取决于您选择了多少点。是否可以一次获取所有选定点并只调用一次 select 事件?

chart: {
renderTo: 'container',
defaultSeriesType: 'scatter',
events: {
selection: function(event) {
for (var i = 0; i < this.series[0].data.length; i++) {
var point = this.series[0].data[i];
if (point.x > event.xAxis[0].min &&
point.x < event.xAxis[0].max &&
point.y > event.yAxis[0].min &&
point.y < event.yAxis[0].max) {
point.select(true, true);
}

}
return false;
}
},
zoomType: 'xy'
},
plotOptions: {
series: {
allowPointSelect: true,
point: {
events: {
'select': function(event){
alert("point selected!");
}
}
}
}
}

http://jsfiddle.net/u18xkger/

我在 highcharts 论坛上找到了这篇文章,但我无法创建所需的行为。 http://forum.highcharts.com/highcharts-usage/drag-selection-around-multiple-points-t31553/#p110834

感谢任何帮助,提前致谢。

最佳答案

在 highcharts 人员提供的帮助下,我通过在选择完成时调用自定义事件解决了这个问题。

 function toast(chart, text) {
chart.toast = chart.renderer.label(text, 100, 120)
.attr({
fill: Highcharts.getOptions().colors[0],
padding: 10,
r: 5,
zIndex: 8
})
.css({
color: '#FFFFFF'
})
.add();

setTimeout(function () {
chart.toast.fadeOut();
}, 2000);
setTimeout(function () {
chart.toast = chart.toast.destroy();
}, 2500);
}

/**
* Custom selection handler that selects points and cancels the default zoom behaviour
*/
function selectPointsByDrag(e) {

// Select points
Highcharts.each(this.series, function (series) {
Highcharts.each(series.points, function (point) {
if (point.x >= e.xAxis[0].min && point.x <= e.xAxis[0].max &&
point.y >= e.yAxis[0].min && point.y <= e.yAxis[0].max) {
point.select(true, true);
}
});
});

// Fire a custom event
HighchartsAdapter.fireEvent(this, 'selectedpoints', { points: this.getSelectedPoints() });

return false; // Don't zoom
}

/**
* The handler for a custom event, fired from selection event
*/
function selectedPoints(e) {
// Show a label
toast(this, '<b>' + e.points.length + ' points selected.</b>' +
'<br>Click on empty space to deselect.');
}

/**
* On click, unselect all points
*/
function unselectByClick() {
var points = this.getSelectedPoints();
if (points.length > 0) {
Highcharts.each(points, function (point) {
point.select(false);
});
}
}

chart: {
type: 'scatter',
events: {
selection: selectPointsByDrag,
selectedpoints: selectedPoints,
click: unselectByClick
},
zoomType: 'xy'
}

以下是引用链接: https://github.com/highslide-software/highcharts.com/issues/4682

关于javascript - highcharts 一次性选择多个点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com