Wait for query results before executing extension method code

I’ve written a function within the configureChart extension function on a Chart component that I’d like to defer execution of until the chart’s SQL query has returned results. My code is working to do what I need to do, but the afterLoad function should be called after chart’s data property SQL query returns results after an update instead of a manual timeout via the system.util.invokeLater function as I have here.

Can someone please point me in the right direction on how to go about this?

def configureChart(self, chart):
	from java.awt import Color

	def afterLoad():
		plot = chart.getCategoryPlot()
		renderer = plot.getRenderer(1)
		ds = chart.getPlot().getDataset(1)
		metricVal = self.Data.getValueAt(0,1)
		targetVal = self.Data.getValueAt(0,2)
		#get y coord based on chart width,
		#then pad the Y coord value to place arrows
		#at correct positions relative to bars
		axis = plot.getRangeAxis()
		area = self.getChartRenderingInfo().getPlotInfo().getPlotArea()
		axisEdge = plot.getRangeAxisEdge()
		yCoord = axis.valueToJava2D(targetVal, area, axisEdge)
		padding = 100+25
		arrowCoord = yCoord+padding
			window = system.gui.findWindow('Production/PlantCostView')[0]
			print 'Cannot find window'
		arrow = window.getRootContainer().getComponent('targetArrowLE')
		print arrowCoord
		system.gui.transform(arrow, newX=arrowCoord)
		#color bars based on performance
		if metricVal >= targetVal:
			renderer.setSeriesPaint(0, Color.GREEN)
			renderer.setSeriesPaint(0, Color.RED)


Have you tried utilizing the propertyChange event handler for the chart? I’m also assuming this in Vision and the ‘Data’ property of the chart has the SQL binding on it?

Place this in the propertyChanged event handler. Since confgureChart() is technically a function of the chart I believe you should be able to call it like you would any other function

if propertyName == 'Data':

The easiest way for this one is to replicate the script from configureChart to property Change when ‘Data’ change. In this scope “chart” won’t be defined. Instead, define it manually with:

chart = event.source.getChart()

There’s a clever way of doing this but you’ll need to ask via message.

where that script should be placed?
Because I see syntax error everywhere.

If you right click the chart component you should see ‘Scripting’ in the list that pops up.

Select that, then on the top left you should see where it says ‘Event Handlers’.

Under that you should see a folder called ‘properyChange’

Expand that folder and select ‘propertyChange’

Then select the ‘Script Editor’ tab in the upper right of the window

Place the script I gave into there. You might have to double check spacing/tabbing, I know the forums can screw with formatting some times.

This is all assuming you are working in vision

well haha.
I’ll just ignore that.
I was being sarcastic.

Not going to lie, I didn’t pay attention and thought you were the original poster asking…

Its been a day :upside_down_face:

Thanks, guys.
@jespinmartin1 , your method works just fine and is a simple change so I’m going to implement as you’ve described.
@ryan.white , as you wrong the call to configure chart from propertyChange, the propertyChange script can’t refer to self to call the fnc. Also tried event.source but that didn’t work either.

I appreciate the quick responses, it took me a little while to circle back to this.