I have the power chart shown below and would like to be able to automatically adjust the y axis range if I deselect certain tags. For instance, supply temp, return temp and DP are all relatively low compared to flow and energy rate, how can I get the power chart to auto adjust the range to show the other closer if i deselect flow and energy rate.
@alec did you happen to find a solution to this? I'm currently looking to do the same thing.
I did not. It was low priority so I moved on to other stuff and actually forgot about it. So if you do find a solution I'd love to see it.
So I came up with a poor work around but it is functional. I use a button, two sliders, and some LED Displays.
When you click the button onClick script, the code looks at the pens in the chart and the date range. It finds the min and max of all tags. It then sets the slider min max values to these found values. Now point your power chart min and max to the value of the appropriate sliders (Must disable autorange). I've only tested with Historical power chart so far.
Adjust the min slider and it adjusts the min range of the power chart. Adjust the max slider and it adjusts the max range of the power chart.
Pros: It kinda works.
Cons: Code is slow to execute. If you change dates, you must hit the button again to get a new autorange.
def runAction(self, event):
# Initialize empty variables
paths = []
temp=""
# Iterate through all the pens in a powerchart, get their source
# and build a list of tag paths.
# My path is from the [default] provider and needed the first 62
# characters removed and the last two.
for pen in self.getSibling("PowerChart").props.pens:
temp = str([pen.data.source])
paths.append("[default]"+temp[62:-2])
# Determine the calculation to use.
calcmax = ["Maximum"]
calcmin = ["Minimum"]
# Define the date range using the range of the PowerChart.
end = self.getSibling("PowerChart").props.config.endDate
start = self.getSibling("PowerChart").props.config.startDate
# Run the query, returning the results as an Ignition dataset.
datamax = system.tag.queryTagCalculations(paths, calcmax, start, end)
datamin = system.tag.queryTagCalculations(paths, calcmin, start, end)
# Parse the dataset and return only the tag values as a list.
M = max(datamax.getColumnAsList(1))
m = min(datamin.getColumnAsList(1))
# Set the values of an LED Display and max slider
self.getSibling("LedDisplay").props.value = M
self.getSibling("Max_Range").props.max = M
self.getSibling("Max_Range").props.min = m
self.getSibling("Max_Range").props.value = M
# Set the values of an LED Display and min slider
self.getSibling("LedDisplay_0").props.value = m
self.getSibling("Min_Range").props.max = M
self.getSibling("Min_Range").props.min = m
self.getSibling("Min_Range").props.value = m
If someone else has a more elegant method, please share. I'm still a poor coder and trying to learn.
You can probably rework my code to only evaluate pens where visible = true. Then click the button and get a new range.
Thanks for posting this, I forgot about this issue and it made me start looking at it again.
Here was the solution I came up with.
I added two custom properties.
list - powerchart_max
list - powerchart_min
I used list because I have a left and right axis so multiple min and max values.
The powerchart_max property has a property binding to this.props.pens
with a script transform with the following code:
start = self.props.config.rangeStartDate
end = self.props.config.rangeEndDate
powerchart_max = [[],[]]
for pen in list(value):
if pen['visible']:
source = pen['data']['source']
pen_max = system.tag.queryTagCalculations(paths=[source], calculations=["Maximum"], startDate=start, endDate=end)
pen_max = pen_max.getValueAt(0,1)
axis_n = ['right','left']
axis = pen['axis']
axis = axis_n.index(axis)
powerchart_max[axis] = powerchart_max[axis] + [pen_max]
if powerchart_max[0] == []:
powerchart_max[0] = [0]
if powerchart_max[1] == []:
powerchart_max[1] = [0]
powerchart_max[0] = max(powerchart_max[0])
powerchart_max[1] = max(powerchart_max[1])
return powerchart_max
The powerchart_min property has a property binding to `this.props.pens` with a script transform with the following code:
start = self.props.config.rangeStartDate
end = self.props.config.rangeEndDate
powerchart_min = [[],[]]
for pen in list(value):
if pen['visible']:
source = pen['data']['source']
pen_min = system.tag.queryTagCalculations(paths=[source], calculations=["Minimum"], startDate=start, endDate=end)
pen_min = pen_min.getValueAt(0,1)
axis_n = ['right','left']
axis = pen['axis']
axis = axis_n.index(axis)
powerchart_min[axis] = powerchart_min[axis] + [pen_min]
if powerchart_min[0] == []:
powerchart_min[0] = [0]
if powerchart_min[1] == []:
powerchart_min[1] = [0]
powerchart_min[0] = min(powerchart_min[0])
powerchart_min[1] = min(powerchart_min[1])
return powerchart_min
I then added the following property bindings:
axes[0].range.min
= this.custom.powerchart_min[0]
axes[0].range.max
= this.custom.powerchart_max[0]
axes[1].range.min
= this.custom.powerchart_min[1]
axes[1].range.max
= this.custom.powerchart_max[1]
This solution seems to work well with minimal latency. Hope this helps!
Update: I added checks for if all values are deselected to set the min/max to 0.
After some troubleshooting I was able to get this script from alec to work on my perspective power chart.
I did everything as he described except:
changed: axis = axis_n.index(axis)
to: axis = axis_n.index('left')
Name both axes
Select the second axes for each pens, pen.axis
This is what worked for me.
Hi Alec,
Hope you are doing good. I am facing the same kind of issue.
I have power chart binding to the historical tag. I have set default time range for 1 hour Realtime. My Y axis value was oscillating according to the value reading in the tag.
I set the Min and Max value and off the auto range to false, still value curve was oscillating when time changes . Can you please provide the solution for this issue.