How to limit the amount of bars in bar chart dynamically?

I have a SQL query that returns the number of connections to a device per day. I want to visualize the development of most used devices per day with a stacked bar chart. For overview purposes, I only want to show the top 10 devices with respect to the currently selected time span. More specifically: When I change the time span, I want the chart to update itself with the appropriate devices that were used the most in this time span.

I probably need to query all records inside the table and make some adjustments inside Grafana but I cannot find the right configuration.

Thanks in advance!

Adjust the query so that it only returns the top ten.

Is there a possibility to enable this without modifying my query? As I want the chart to dynamically update on time range change, Grafana needs to have access to all records in the table, doesn’t it?

When changing the query is necessary, do I need to work with the $__timeFrom() and $__timeTo() macros to achieve my goal?

Can you explain in more detail what you mean by the top ten? Poosibly give some sample data.

I found out that I certainly can just limit the query. Just used the wrong macros!
Problem solved, thanks!