Version 8.1.44 Vision
I have an easy chart that uses historical pens. I want the y axis to be auto ranging around 5%, but even when configuring this, if my minimum values are 0 or near 0 the 5% margin does not appear because it doesn't cross 0 to show negative range values.
I already have a custom method on my easy chart that determines min and max values over my historical range so I can easily figure out the lowest datapoint value.
Is there a way, from this custom method, that I can I disable auto range to set my lower bound and turn back on auto range?
I can't seem to get a reference to the chart from the method so this fails:
# Set your start and end dates
s = self.startDate
e = self.endDate
# Convert tagPens to a Python dataset
newTagPens = self.tagPens
tagPens = system.dataset.toPyDataSet(self.tagPens)
# Loop through the tag pens and retrieve min, max values from the tag history
for i in range(len(tagPens)):
pen = tagPens[i]
tagPath = pen["TAG_PATH"]
minValue = None
maxValue = None
avgValue = None
try:
historyValues = system.tag.queryTagHistory(
paths=[tagPath, tagPath, tagPath],
startDate=s,
endDate=e,
returnSize=1,
columnNames=['%sMin', '%sMax', '%sAvg'],
aggregationModes=['Minimum', 'Maximum', 'Average']
)
if historyValues.getRowCount():
minValue = historyValues.getValueAt(0, 1)
maxValue = historyValues.getValueAt(0, 2)
avgValue = historyValues.getValueAt(0, 3)
except:
pass
# Only adjust if minValue is valid and less than 5
if minValue is not None and minValue < 5:
lowerBound = minValue - (maxValue - minValue) * 0.05
chart = self
chart.setAutoRange(False) # Temporarily disable auto-range to set custom bounds
chart.getYAxes().get(0).setLowerBound(lowerBound) # Set lower bound for Y-axis
chart.setAutoRange(True) # Re-enable auto-range for the upper bound