Display the time axis(X-axis) of the graph panel defined by a template variable

Currently

Database: InfluxDB

Panel Type: Graph

I have a template variable for Year (derived in the script from the timestamp). I use this to select the data for a particular year (2017, 2018, 2019, 2020 etc.).

The issue is I have to select the time range (upper right of dashboard) appropriately as well. So, if I want to show the data of 2019, I need to select Last 2 years for example. The problem with this is that even though I see the data of 2019, the time axis comprises of two years. So, it’s empty for half of its width.

I can of course choose Previous year or 2019 under absolute date range. But, this is not flexible anymore.

What I want:

When I select 2019 from the template variable, the timerange should align to 2019 as well the (it’s ok if it can be done for individual panels and not for the whole dashboard) and so on for other years.

Or, only those parts of time axis should be visible which have corresponding data in the Y-axis.

So, are there any workarounds which might solve this?