Error Power chart



Here is the error that is displayed

Traceback (most recent call last): File "<transform>", line 24, in transform at java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source) at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Unknown Source) at java.base/jdk.internal.util.Preconditions.checkIndex(Unknown Source) at java.base/java.util.Objects.checkIndex(Unknown Source) at java.base/java.util.ArrayList.get(Unknown Source) at com.inductiveautomation.ignition.gateway.datasource.BasicStreamingDataset.getValueAt( at jdk.internal.reflect.GeneratedMethodAccessor54.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.lang.IndexOutOfBoundsException: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

Voici le code

	# If timeSelection is 0, set minutes equal to minutes param.
	if value['timeSelection'] == 0:
		minutes = value['minutes']
		# Otherwise, get the amount of minutes based on the
		# timeSelection. 1M=1min,1H=60min,1D=1440min,1W=10080min.
		minuteMap = {1:1,2:60,3:1440,4:10080}
		minutes = minuteMap[value['timeSelection']]
	# Query the historical data using now() as the endTime and
	# 0 - minutes (figured out minutes above) as the startTime,
	# and then put the data in a format expected by the chart
	# and return it.
	data = []
	if value['tag'] != '':
		path = value['tag']
		system.perspective.print('querying data for: ' + str(path))
		endTime =
		startTime =,(0-minutes))
		history = system.tag.queryTagHistory(paths=[path],startDate=startTime,endDate=endTime,aggregationMode='LastValue',returnSize=300,noInterpolation=0)
		#return history.getValueAt(0,1)
		if history.getValueAt(0,1) == None:
			return data
			for x in range(0,history.getRowCount()):
	return data

I would like this error not to appear when there is no historical data recorded in the database

For exemple if I want show data in most last 30 min and if I haven't stored data in this time, this power chart show me error.

How can I avoiding this Error

Then you'll have to check for the dataset length before trying to reference values from it.

Is trying to get something from an empty dataset.

While I'm at it, there are a few things you can change in your script:

  • you don't need to compute a startDate if the endDate is now. You can use rangeMinutes instead.
  • you can include value[minutes] in your minuteMap to make things a bit simpler.

# no path provided, return empty list
if value['tag'] == '':
	return []

minuteMap = [value['minutes'], 1, 60, 1440, 10080]
minutes = minuteMap[value['timeSelection']]

history = system.tag.queryTagHistory(

return [
		'time':, 0)),
		'value': history.getValueAt(x, 1)
	} for x in xrange(history.getRowCount())