How to set same y-axis value in multiple axis with dynamic data also, the bar count should get increase based on the dynamic data?

Hello,
I am new to Plotly, I am trying to create a bar graph in stack barmode with dynamic data. The scenario is, we have changing x-axis with minimum of 1 to maximum of 300(default is 100) and y-axis up to 300 always but it can be configurable with maximum of 600. So based on the x-axis value we have to create the bar graph, for example if the x-axis value is 100 then we should have 100 bars in the graph with two traces. Also, the x-axis should be on the top and y-axis should display on both left and right with same values(Max up to 600).

Below is my tried example, I couldn’t able to achieve my expectation. Please help me for this.

Here is my example