# Selectable bar graph still shows selection after graph chnge

**URL:** <https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605>\
**Category:** Archived Topics\
**Created:** [March 14, 2008, 9:27pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605 "2008-03-14T21:27:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 14, 2008, 9:27pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/1 "2008-03-14T21:27:24Z")

</div>

I have a bar graph that has selection enabled. When I click on a bar, that generates a new query for another graph. In this way I am drilling down into the equipment downtime problem.

I notice that when the graph is redrawn because of a change, the highlight around the bar that was selected is still there, even though the bar is drawn in a different location. Everything functions correctly, but the outline is still over the graph. Do I need to reset that some how, or change a setting when the graph refreshes?

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 14, 2008, 9:28pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/2 "2008-03-14T21:28:47Z")

</div>

Sorry, I posted this in the SQL portion and it was supposed to go under the PMI forum.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 14, 2008, 10:29pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/3 "2008-03-14T22:29:25Z")

</div>

Hmm, we should probably reset the selection when the data changes. in the meantime, if you toggle the selectionEnabled, that should clear the selection.

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 14, 2008, 11:26pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/4 "2008-03-14T23:26:39Z")

</div>

I put the following lines in the chart “event propertychange”

if event.propertyName == ‘Data’:  
event.source.selectionEnabled = 0  
event.source.selectionEnabled = 1

Thinking that when the data changed, it would toggle the selection enabled option but it did not seem to make any difference.

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 17, 2008, 5:41pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/5 "2008-03-17T17:41:48Z")

</div>

Sorry, it turns out that toggling selectionEnabled won’t do what you want (as you discovered) in version 3.1.6.

We’ll add the ability to clear the chart selection programmatically in the next release, but until then, here is a hack that’ll clear it. You’d put this on the chart’s propertyChange event like you tried to before:

`if event.propertyName == 'Data':
   chart = event.source
   from java.awt.event import MouseEvent
   click = MouseEvent(chart, MouseEvent.MOUSE_CLICKED, event.when, 0,0,0,1,0)
   chart.dispatchEvent(click)`

Hope this helps,

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 17, 2008, 6:05pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/6 "2008-03-17T18:05:35Z")

</div>

Thanks Carl,  
But I still have a problem. I’m not sure if I put it in the correct location, with regard to the rest of the script, but now I am getting the following error. It looks like it doesn’t like the when portion.

Traceback (innermost last):  
File “”, line 10, in ?  
AttributeError: instance of ‘java.beans.PropertyChangeEvent’ has no attribute ‘when’

Here is the script, with the new portion.

#Create 2nd dataset for line graph portion  
if event.propertyName == ‘Data’:  
#Work around to clear outline of selected graph part  
chart = event.source  
from java.awt.event import MouseEvent  
click = MouseEvent(chart, MouseEvent.MOUSE\_CLICKED, event.when, 0,0,0,1,0)  
chart.dispatchEvent(click)

```
data = fpmi.db.toPyDataSet(event.newValue)
headers = ["x","Cumulative"]

# First, calculate the total
total = 0
for row in data:
	total += row[1]

# Now, generate the new dataset
rows = []
pct = 0
for row in data:
	if total > 0:
		pct += (float(row[1])/float(total))*100
	rows.append([row[0], pct])

event.source.Cumulative = fpmi.db.toDataSet(headers,rows)
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [March 17, 2008, 6:12pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/7 "2008-03-17T18:12:19Z")

</div>

My mistake, try this:

[code]#Create 2nd dataset for line graph portion  
if event.propertyName == ‘Data’:  
#Work around to clear outline of selected graph part  
chart = event.source  
from java.awt.event import MouseEvent  
when = java.lang.System.currentTimeMillis()  
click = MouseEvent(chart, MouseEvent.MOUSE\_CLICKED, when, 0,0,0,1,0)  
chart.dispatchEvent(click)

data = fpmi.db.toPyDataSet(event.newValue)  
headers = [“x”,“Cumulative”]

# First, calculate the total

total = 0  
for row in data:  
total += row[1]

# Now, generate the new dataset

rows = []  
pct = 0  
for row in data:  
if total \> 0:  
pct += (float(row[1])/float(total))\*100  
rows.append([row[0], pct])

event.source.Cumulative = fpmi.db.toDataSet(headers,rows)[/code]

Also, please use the [code] block when posting code to the forum to preserve formatting. (See [inductiveautomation.com/foru … ode=bbcode](http://www.inductiveautomation.com/forum/faq.php?mode=bbcode) for more info)

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 18, 2008, 8:41pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/8 "2008-03-18T20:41:15Z")

</div>

Thanks for the code, but I still get this error:

Traceback (innermost last):  
File “”, line 6, in ?  
NameError: java

Any idea why? Should I just be waiting for the next release when this problem will be addresses?

---

<div class="post-metadata">

**Author:** ![MickeyBob](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MickeyBob](https://forum.inductiveautomation.com/u/MickeyBob)\
**Post date:** [March 18, 2008, 11:47pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/9 "2008-03-18T23:47:30Z")

</div>

[quote]Thanks for the code, but I still get this error:

Traceback (innermost last):  
File “”, line 6, in ?  
NameError: java

Any idea why? Should I just be waiting for the next release when this problem will be addresses?[/quote]

This would indicate to me that you have not imported the appropriate java package. Try adding

[code]import java.lang.System

[/code]before

```auto
when = java.lang.System.currentTimeMillis()
```

---

<div class="post-metadata">

**Author:** ![Ron](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@Ron](https://forum.inductiveautomation.com/u/Ron)\
**Post date:** [March 19, 2008, 2:43pm UTC](https://forum.inductiveautomation.com/t/selectable-bar-graph-still-shows-selection-after-graph-chnge/605/10 "2008-03-19T14:43:52Z")

</div>

That was it. Works like a charm now. Thanks a lot.
