title: Javafx bar chart X axis does not scale properly when updating data
body: <p>I am trying to implement a bar chart using Javafx. The chart works fine if I plot the data only once. But when I update the data and re-plot the chart, the X axis scale remains the same, while all data is updated correctly. Please check the following images.</p>
  
  <p>This is the correct chart which plots data by weeks</p>
  
  <p><a href="https://i.stack.imgur.com/C7WxN.png" rel="nofollow noreferrer">data by week</a></p>
  
  <p>When I update the data, the chart turns into</p>
  
  <p><a href="https://i.stack.imgur.com/v3t8F.png" rel="nofollow noreferrer">data by month</a></p>
  
  <p>You can see the data has been updated, but the X axis does not scale correctly. Interesting thing is, when I plot the chart again without changing the data, the X axis becomes normal like this.</p>
  
  <p><a href="https://i.stack.imgur.com/yBVeV.png" rel="nofollow noreferrer">data by month2</a></p>
  
  <p>The codes are as follows:</p>
  
  <pre><code>private static void drawChart(int timeMode)
  {
      stayAvg = new XYChart.Series&lt;String, Number&gt;();
      stayAvg.setName("Avg.Stay (mins)");
  
      // add data to the dataset
      if (timeMode == 1)
      {
          for (int i = firstWeek; i &lt;= lastWeek; i++)
          {
              stayAvg.getData().add(new XYChart.Data&lt;String, Number&gt;(weeks[i], weeksTotalCount[i]));
          }
      }
      else if (timeMode == 2)
      {
          for (int i = firstMonth; i &lt;= lastMonth; i++)
          {
              stayAvg.getData().add(new XYChart.Data&lt;String, Number&gt;(months[i], monthsTotalCount[i]));
          }
      }
  
      // display chart
      Platform.runLater(new Runnable() {
          @Override
          public void run() {
              // plot data sets to the chart
              // Update UI here.
              // set up tooltips when cursor hovers on bars
              sbc.setData(FXCollections.observableArrayList(stayAvg));
              stayAvg.getData().forEach(d -&gt; {
                      Tooltip tip = new Tooltip();
                      tip.setText(d.getYValue() + "\n" + d.getXValue());
                      Tooltip.install(d.getNode(), tip);
              });
              // sbc is a StackedBarChart
              sbc.setTitle("Average Stay");
              chart.setScene(scene);
          }
      });
  }
  </code></pre>