Issue while displaying value in gauge

Hello,

I have disabled the label values of gauge component and by using value or maxvalue , I am trying to display the values for gauge but it is not working.
I have attached the snapshot of the script below -

	devices_data = sum([durations['ON'] / 60 for address, durations in address_durations.items()])

    # Calculate per minute consumption
	minute_consumption_kwh = hourly_consumption_kwh / 60
	print(minute_consumption_kwh)
	
	duration_data = minute_consumption_kwh * devices_data

    # Format the values for display
	total_kwh_consumed_with_unit = "{:.2f}kwh".format(duration_data)
	print(total_kwh_consumed_with_unit)
	
	# Calculate the difference
	difference_kwh  = total_consumption_str - duration_data
	
	# Format the values for display
	difference_with_unit = "{:.2f} kWh".format(difference_kwh)
	print("Difference:", difference_with_unit)
	
	
	#Updating in gauge component
	gauge_day = self.parent.parent.parent.getChild("FlexContainer_1").getChild("FlexContainer_0").getChild("Gauge")
	gauge_week = self.parent.parent.parent.getChild("FlexContainer_1").getChild("FlexContainer_0").getChild("Gauge_0")
	gauge_month = self.parent.parent.parent.getChild("FlexContainer_1").getChild("FlexContainer_0").getChild("Gauge_1")
	
	# Now, depending on the duration_type, update the corresponding gauge
	if duration_type == 1:  # Daily
	    gauge_day.props.outerAxis.maxValue = difference_with_unit
	    print("Daily gauge updated:", difference_with_unit)
	elif duration_type == 7:  # Weekly
	    gauge_week.props.outerAxis.maxValue = difference_with_unit
	    print("Weekly gauge updated:", difference_with_unit)
	elif duration_type == 30:  # Monthly
	    gauge_month.props.outerAxis.maxValue = difference_with_unit
	    print("Monthly gauge updated:", difference_with_unit)

It would be really helpful if anyone can please help me out with this issue?

Thanks in advance!

I don't understand what you are trying to do but I think that all your parent.parent.parent.getChild().getChild().getChild() code makes your application very brittle. If you move anything into another container it will break.
I recommend that you set up some custom properties on the view and write the values to those. Then bind your gauge properties to those.

I would also try to do all this with expression functions rather than a script. You could have custom props for calculated daily, weekly and monthly and switch the gauge bindings based on duration_type.

You have one occurrence of "{:.2f}kwh". It should be "{:.2f}kWh" (capital W for watt).

2 Likes