title: How can I update JavaFX BarChart in Swing application?
body: <p>I want to update a JavaFX BarChart. I initialize my BarChart with this method:</p>
  
  <pre><code>private void initFxComponents(String questionName){
  
      Platform.runLater(() -&gt; {
          final CategoryAxis xAxis = new CategoryAxis();
          final NumberAxis yAxis = new NumberAxis();
          final BarChart&lt;String, Number&gt; barChart = new BarChart&lt;&gt;(xAxis,yAxis);
          barChart.setTitle(questionName);
          barChart.setLegendVisible(false);
          xAxis.setLabel("Answer");       
          yAxis.setLabel("Number of times answered");
          series = new Series();
          int nbAnswersForProposal;      
          String proposal;
          for(Proposal p : question.getListProposals()){
              nbAnswersForProposal = Answers.getInstance().getNbAnswersForProposal(quiz.getId(), question.getId(), p.getId());
              proposal = p.getProposal();                               
              StringBuilder sb = new StringBuilder(proposal);
              int i = 0;
              while ((i = sb.indexOf(" ", i + 30)) != -1)
                  sb.replace(i, i + 1, "\n");                
              series.getData().add(new Data(sb.toString(), nbAnswersForProposal));
          } 
          Scene scene = new Scene(barChart,800,800);
          barChart.getData().addAll(series);
          fxPanel.setScene(scene);
      });
  
  }
  </code></pre>
  
  <p>I use this method to update data:</p>
  
  <pre><code>public void updateData(){
      Platform.runLater(() -&gt; {
          series.getData().clear();
          int nbAnswersForProposal;       
          String proposal; 
          for(Proposal p : question.getListProposals()){
              nbAnswersForProposal = Answers.getInstance().getNbAnswersForProposal(quiz.getId(), question.getId(), p.getId());
              proposal = p.getProposal();                               
              StringBuilder sb = new StringBuilder(proposal);
              int i = 0;
              while ((i = sb.indexOf(" ", i + 30)) != -1)
                  sb.replace(i, i + 1, "\n");
              series.getData().add(new Data(sb.toString(), nbAnswersForProposal));
          }
      });
  }
  </code></pre>
  
  <p>But when I update data, BarChart is wrong and doesn't display data correctly. I think I'm not doing the right thing to update my BarChart, can anyone help me ?
  Thanks !</p>