Hello team!
I have to compare 2 charts from 2 different years. I´m using a SplitContainer for this and is looking great...but...the only issue I´ve got is that the Y Axis value is not equivalent on the left and the right, so if you are not paying attention is hard to compare with non equivalent Y-axis. As you can see in this example, the mismatched Y-axis scales can be misleading.
Any ideas of how to make both charts Y-axis equivalent for easy comparison?
Thanks
You could add a custom property to the view to bind the range if you're using the XY chart:
1 Like
If you can create custom properties, chart1Max
and chart2Max
holding the maximum value of each chart, then you can use an expression binding to find the higher value and another expression binding to create the yMax value.
Expression binding for yAxisMax:
max({this.custom.chart1Max}, {this.custom.chart2Max})
Usually we want the yMax value to be a nice round number such as 1 × 10x, 2 × 10x, 5 × 10x, for example so that the grid labels will be nice round values.
Expression transform:
// This function will return the next highest number
// in the series 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, etc.
// e.g. For value = 123, {value} / 10 ^ floor(log10({value}) returns 2,
// the number's power of ten = 2.
// {value} / 10 ^ floor(log10({value}) will return 1.23.
// https://forum.inductiveautomation.com/t/chart-graph-comparison-with-splitcontainer/102789/3
if({value} / 10 ^ floor(log10({value})) < 2,
2 * 10 ^ floor(log10({value})),
if({value} / 10 ^ floor(log10({value})) < 5,
5 * 10 ^ floor(log10({value})),
10 * 10 ^ floor(log10({value}))
)
)
You could use a script transform instead. It's easier to read and understand but the expression will probably run faster.
Script transform version
def transform(self, value, quality, timestamp):
import math
pow = math.floor(math.log10(value))
num = value / 10 ** pow
if num < 2:
return 2 * 10 ** pow
elif num < 5:
return 5 * 10 ** pow
else:
return 10 * 10 ** pow
1 Like
Yes, great! thanks Benjamin and Transistor. I just binded the max and min values
I just used the expression you wrote and its working enough well for me.
max({this.custom.chart1Max}, {this.custom.chart2Max})
for max values and
min({this.custom.chart1Min}, {this.custom.chart2Min})
for min values,
I get the max value with a Script Transform for binded dataset:
if value and hasattr(value, 'getColumnNames'):
column_name = "AVG_KWIT"
if column_name in value.getColumnNames():
# Extract values from the column
avg_kwit_values = [row[column_name] for row in system.dataset.toPyDataSet(value) if row[column_name] is not None]
# Find the maximum value, ensuring there are values to compare
max_value = max(avg_kwit_values) if avg_kwit_values else None
else:
max_value = None
else:
max_value = None
# Return the maximum value
return max_value if max_value is not None else "No Data"

1 Like