Change Power Chart Data Depending on Dropdown Value

Hello there everyone,

I have been trying and I was wondering if it could be possible for the data displayed on a Power Chart to change depending of the selected option on a Dropdown Menu. The view design would be the following:

As it can be seen, there's only a dropdown menu and a Power Chart component. The Dropdown Menu has the following configurations:

image

The idea I am trying to implement is a Change Script on the "value" option of the Dropdown menu, so when the value changes, so will the data on the powerchart, along the Pen name displayed. Here's what I'm trying to do, using every historic path tag on the chart.props.pens.data.source expresion:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):

	selected = currentValue.value
	chart = self.getSibling("PowerChart")
	
				SUM_FIT_01 = "histprov:SQLServer:/drv:ignition-XXX-XX:default:/tag:derived tags/sum_fit_01_mins"

                 #Same goes for the rest of tags				
		
				if selected == 0:
					chart.props.pens.data.source = SUM_FIT_01
					chart.props.pens.name = "A"
				
				elif selected == 1:
					chart.props.pens.data.source = SUM_FIT_02
					chart.props.pens.name = "B"
					
				elif selected == 2:
					chart.props.pens.data.source = SUM_FIT_04
					chart.props.pens.name = "C"
					
				elif selected == 3:
					chart.props.pens.data.source = SUM_CC_01
					chart.props.pens.name = "D"
					
				elif selected == 4:
					chart.props.pens.data.source = SUM_DP_01
					chart.props.pens.name = "E"
					
				elif selected == 5:
					chart.props.pens.data.source = MEAN_CLIT_01
					chart.props.pens.name = "F"
					
				elif selected == 6:
					chart.props.pens.data.source = MEAN_OIT_01
					chart.props.pens.name = "G"

When trying to run the application, this message error appears:

image

How could I solvent this problem in order to work? Thanks in advanced

You have an error message that says "code could not be compiled".
You have not given us the actual code you're attempting to run. Or the full details of the error message, which might also have useful information.

The indentation is wrong in the code you posted but we can't be sure unless you post it all.

Sorry for all the inconvenience caused. I found the error and now it seems to work as expected.

The error was on the scripting, when referencing to the pen containing the displayed data. Being the pen '0' the only one created, the referencing was the missing element. So for example, when the selected value is 0, the code would be the following:

	if selected == 0:
		chart.props.pens[0].data.source = SUM_FIT_01
		chart.props.pens[0].name = "A"

The missing element was the [0] next to the pens. Again, sorry for all the inconveniences caused