Generate bar chart with jinja if statement for axes' element


I am trying to use the if statements to assign the elements for x and y axis using Plotly. It is not generating the correct chart and I am not sure if this method works. The chart should have 8 elements/bars on the x axis because of the stored values but I am getting only the values on the chart or 2 bars coming from the last if statement.

I am using flask and the above code is using the jinja version of if statements.

Can someone guide me with this?

Thank you