How do I Set Multiple DataSet Values with one button?

I have an EasyChart and I want a single button to reset 6 pens to their default colors. I already have the Hex code for their colors. I also have code that will change to color of a single pen. I am not strong with Python scripting at all. Somebody please help me out.

THIS CODE WORKS:
pens = event.source.parent.getComponent(‘Easy Chart’).tagPens
newDS = system.dataset.setValue(pens, 0, “COLOR”, “FF5555”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

THIS CODE DOESN’T WORK: (I think I know why)
pens = event.source.parent.getComponent(‘Easy Chart’).tagPens
newDS = system.dataset.setValue(pens, 0, “COLOR”, “FF5555”)
newDS = system.dataset.setValue(pens, 1, “COLOR”, “FF5555”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

So since that code didn’t work, I tried this.
THIS CODE DOESN’T WORK EITHER: (I have no idea why not)
pens = event.source.parent.getComponent(‘Easy Chart’).tagPens

newDS = system.dataset.setValue(pens, 0, “COLOR”, “FF5555”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

newDS = system.dataset.setValue(pens, 1, “COLOR”, “5555FF”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

newDS = system.dataset.setValue(pens, 2, “COLOR”, “55FF55”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

newDS = system.dataset.setValue(pens, 3, “COLOR”, “FF55FF”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

newDS = system.dataset.setValue(pens, 4, “COLOR”, “55FFFF”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

newDS = system.dataset.setValue(pens, 5, “COLOR”, “FFAFAF”)
event.source.parent.getComponent(‘Easy Chart’).tagPens = newDS

Hi jjanowiak

your code won’t work correctly as you want because “system.dataset.setValue” can only change one value at a time, see here:

https://docs.inductiveautomation.com/display/DOC/system.dataset.setValue

To do what you want you have to read the dataset, alter the dataset and the write to the dataset for each individual change.

This is ideal for a “for” loop, in my example below (there are other ways) I have done the following:

Read the tagPens dataset.
Make a list of the default colours in order
measure the length of the list
make a “for” loop for the length of the list, starting at 0, n will be the pen number as its loops (or more correctly the dataset row number). n is also the index of the colour in the list.
write the new value for each pen in turn, the dataset overwriting itself each time.
write the final version to the easy-chart.

pens = event.source.parent.getComponent('Easy Chart').tagPens hue=["FF5555","5555FF","55FF55","FF55FF","55FFFF","FFAFAF"] hueLen = len(hue) for n in range (0,hueLen): pens = system.dataset.setValue(pens, n, "COLOR", hue[n]) event.source.parent.getComponent('Easy Chart').tagPens = pens

I hope that makes some sense.