Trying to add plots to Time Series Chart with script

I am attempting to add/remove plots on a TimeSeriesChart with a script that builds the plots array with a changescript on the parameter NumberValues.

The script works perfectly when in designer, but throws a type error exception when I try to append to the plots property in runtime.

Some help on this would be much appreciated, or an explanation of why it will not work.

Thanks!

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	numbervalues = self.params.NumberValues
	system.perspective.print("numbervalues" + str(numbervalues))
	plots = self.getChild("root").getChild("FlexContainer").getChild("TimeSeriesChart").props.plots
	system.perspective.print("beginninglen" + str(len(plots)))
	plottemps = self.custom.PlotTemplates
	plotslen = len(plots)
	plot1 = plottemps[0]
	plot2 = plottemps[1]
	plot3 = plottemps[2]
	
	while plotslen > 0:
		del plots[plotslen - 1]
		plotslen -= 1
	system.perspective.print("deletedlen" + str(len(plots)))

	while numbervalues > 0:
		system.perspective.print("loopvalues" + str(numbervalues))
		try:
			plots.append(plottemps[numbervalues - 1])
		except: 
			e = sys.exc_info()[0]
			system.perspective.print(e)
		numbervalues -=1
	system.perspective.print("rebuiltlen" + str(len(plots)))

Can you provide more info on the type error exception? Like is it happening in the try/except block near the end, and/or does it tell you what type(s) are causing the failure? Weird that it works only in the designer -- makes me think a certain value or parameter may have an improper persistence setting somewhere on that page.

1 Like

Thanks for your quick reply!

In the course of getting more information for you, I solved the problem.

The full exception read as follows:

(<type 'exceptions.TypeError'>, TypeError("unsupported operand type(s) for -: 'unicode' and 'int'",), <traceback object at 0x2>)

It looks like self.params.NumberValues was being read as a string; I wrapped an int() around it and everything works great now.

This doesn't explain why it worked in designer but not in the browser, which I would love to hear if anyone knows the answer