It depends on the details what exactly you're trying to show. Generic answer to your generic question:
Use calculated dimension with "if" condition or with set analysis limiting years, and use "suppress when null" for this dimension
Use conditions or set analysis to limit years in all expressions, in combinatiion with "suppress 0 values"
Edit: Or create additional "Limited Year" dimension in the script and use it in your bar chart. This one is best for the front end performance, if it matters in your case.