[英]Unselect and Select Event
I am using this fiddle - https://jsfiddle.net/BlackLabel/3tqkjLoh/6/我正在使用这个小提琴 - https://jsfiddle.net/BlackLabel/3tqkjLoh/6/
Here the issue - When I select other point from the previous point of the pie (without unselecting the previous one).这里的问题 - 当我从饼图的前一点中选择其他点时(不取消选择前一点)。 It shows the status of unselect event of the previous point.它显示了前一点的取消选择事件的状态。 I want the status of both 'selected the current one and unselected the previous one'我想要'选择当前一个和取消选择前一个'的状态
const content = document.getElementById('content');
const chart = Highcharts.chart('container', {
chart: {
type: 'pie'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
point: {
events: {
select: function(event) {
const selected = this;
if (selected) {
content.textContent = selected.options.name
/* do something */
// fetch(`/api?id=${ selected.options.id }`)
} else {
content.textContent = 'nothing'
}
},
unselect: function () {
content.textContent = 'unselect event: ' + this.options.name
}
}
}
},
},
series: [{
data: [{
y: 20,
"name": "click me",
}, {
y: 60,
"name": "click me foo",
selected: true,
sliced: true,
}, {
y: 100,
"name": "click me bar",
}, {
y: 100,
"name": "click me baz",
}, ]
}]
});
Here's the problem, selected event triggers before unselect event So basically, content.textContent
is first set to selected.options.name
, and then again sets to 'unselect event: ' + this.options.name
and then the latest value is appeared onto the DOM.问题来了, selected 事件在 unselect 事件之前触发 所以基本上, content.textContent
首先设置为selected.options.name
,然后再次设置为'unselect event: ' + this.options.name
然后最新的值出现在DOM。
https://jsfiddle.net/devatquarxps/5yb0wehd/7/ https://jsfiddle.net/devatquarxps/5yb0wehd/7/
const content = document.getElementById('content'); const chart = Highcharts.chart('container', { chart: { type: 'pie' }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', point: { events: { select: function(event) { const selected = this; selected ? content.textContent ='select event: ' + selected.options.name + ' | ' : content.textContent = '' }, unselect: function () { content.textContent =content.textContent + ' unselect event: ' + this.options.name } } } }, }, series: [{ data: [{ y: 20, "name": "click me", }, { y: 60, "name": "click me foo", selected: true, sliced: true, }, { y: 100, "name": "click me bar", }, { y: 100, "name": "click me baz", }, ] }] });
<script src="https://code.highcharts.com/highcharts.js"></script> <h3 style="color: red">open console panel</h3> <p> After clicking, [selected and sliced] status is not synchronized update; </p> <div> <h5>Show to users</h5> <h6>You have chosen :</h6> <p id="content"></p> </div> <div id="container" style="height: 400px"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.