# Deselect Item in XY Chart

**URL:** <https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549>\
**Category:** Ignition\
**Tags:** python, scripting, ignition81, perspective\
**Created:** [January 29, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549 "2025-01-29T14:11:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Waizmann](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Alexander\_Waizmann](https://forum.inductiveautomation.com/u/Alexander_Waizmann)\
**Post date:** [January 29, 2025, 2:11pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/1 "2025-01-29T14:11:50Z")

</div>

Hi!

I am creating a system in Perspective where a user can click on a bullet data point on an XY chart, which launches a popup to edit that data, and then closes and is supposed to deselect the point on the XY chart. However, I am having trouble causing the selected point to deselect, it usually remains selected after the popup closes.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/26d5782f91278be41c4e6982e36f658d17ba57e6.png)

Attached is the image of the UndoSelection message handler on the XY Chart, which is meant to disable and re-enable selection on the chart, which should cause the chart's selected field to revert to an empty array. This is a way to get around the read-only attribute of the selected.data field. But, this script does not behave as expected. The data array does not seem to properly clear

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 29, 2025, 2:40pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/2 "2025-01-29T14:40:41Z")

</div>

Try this:  
`self.props.selection.data = []`

---

<div class="post-metadata">

**Author:** ![Alexander\_Waizmann](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Alexander\_Waizmann](https://forum.inductiveautomation.com/u/Alexander_Waizmann)\
**Post date:** [January 29, 2025, 4:38pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/3 "2025-01-29T16:38:54Z")

</div>

This did the trick on the selection front, but the chart did not revert to the colors it formerly had before the selection. New rabbit hole found!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 29, 2025, 6:53pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/4 "2025-01-29T18:53:46Z")

</div>

The problem with your original message handler seems to be that toggling `selection.enabled = False` and then `True` again means the chart component never notices the transition. You could insert an evil `sleep` command in there, but try this event-driven alternative instead:

- On the XY Chart, create a custom property `selectionResetTime : 0`.
- Create an expression binding on `selection.enabled`:  
`now(1000) - {this.custom.selectionResetTime} > 1000`  
This will re-enable the selection one second or so after it has been reset by the message handler below.

```python
def onMessageReceived(self, payload):
	self.props.selection.enabled = False
	self.props.selection.data = []
	self.custom.selectionResetTime = system.date.now()

```

The chart will redraw and the selection color will be reset.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 29, 2025, 7:25pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/5 "2025-01-29T19:25:03Z")

</div>

> [@Transistor](#):
>
> try this event-driven alternative instead

That can fail if there is any comms hiccup. Instead, you should rely on something that comes from the browser as a result of disabling selection. Like, the selection disappearing. Consider **not** clearing the selection from the script, just disable selection. And only do that if the selection is already non-empty. A change event on `selection.data` can then re-enable selection when it goes empty.

I recommend similar techniques for all Perspective components that support selection of some kind. Leverage the natural round trip timing instead of an arbitrary sleep duration. It also avoids excess CPU load from unnecessary polling expression bindings (\* _cough_ \* `now()`).

---

<div class="post-metadata">

**Author:** ![Alexander\_Waizmann](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Alexander\_Waizmann](https://forum.inductiveautomation.com/u/Alexander_Waizmann)\
**Post date:** [January 30, 2025, 1:32pm UTC](https://forum.inductiveautomation.com/t/deselect-item-in-xy-chart/101549/6 "2025-01-30T13:32:46Z")

</div>

This recommendation did the trick. It seems the first way of doing the message handlers caused the component to miss the call to the handler that refreshed the datasource, and so the colors didn't revert. Now they are reverting as expected! Thank you, Wayne Gretzky of the Ignition forums
