Script for changing PowerChart trends using a button?

Trying to configure a script to allow simple button navigation for changing the pen displayed on a PowerChart. Example being clicking the Current button will display Current values pulled from the historian, versus clicking the Valve Position button will display Valve Position values, etc. All of this to avoid technicians having to manually use the chart tag browser to find the respective tags.

Currently I have an event script tied to the button click that’s as follows:

powerChart = self.getSibling(“PowerChart”)

powerChart.props.pens[0].data.source = “histprov:Sample_DB:/sys:myGateway:/prov:My_Provider:/tag:My_Folder”

Though it is writing the specified source to the data.source property, it’s not displaying any pen, and I cannot determine why. Any ideas?

First question would be do you actually want to use a powerchart object? If you want something simply for the techs to just see values and you’re already populating the tags you may be better served with a time series chart object instead.

Otherwise to make this work in a powerchart you also need to assign a name to it for it to work.

{
  "data": {
    "source": "histprov:abc:/drv:xyz:default:/tag:tagA"
  },
  "name": "tagA"
}

Though if you're making it more robust and going to add multiple pens to the Chart, you should consider adding logic to check if a pen of the same name already exists to prevent duplicates. As well as a nice feature would be a colorlist and incrementing the color each pen added.

The hope was to see values historically or in real time so as to see exactly how different machines are compensating when another goes down, also the ability to use the xtrace/rangebrush/etc. is useful as well.

Good idea regarding the duplicate pens, I’ll look into that as well.