Highlight high or critical values

Hi, I’m struggling to get this type of threshold display as the threshold cannot be dynamic. I have a metric from which I’m reading the count of no of ports for a particular system. I want to put a threshold value which I can get from another query. How can I do that? Could anyone help me with the queries and config to achieve this? Attaching a screenshot of the bar graph on which I need the dynamic threshold.