title: Update BarChart Series dynamically
body: <p>I want to create dynamic BarChart from HashMap values. In my case I have <code>HashMap&lt;String, Integer&gt;</code>. I want String to be the name of the column and Integer the value of the column. I tried this example:</p>
  
  <pre><code>StackedBarChart&lt;String, Number&gt; sbc;
      CategoryAxis xAxis;
  
      public StackedBarChart&lt;String, Number&gt; initBarChart()
      {
          xAxis = new CategoryAxis();
          NumberAxis yAxis = new NumberAxis();
          sbc = new StackedBarChart&lt;&gt;(xAxis, yAxis);
          sbc.setAnimated(false);
  
          sbc.setTitle("Data Summary");
          sbc.setCategoryGap(55);
  
          yAxis.setLabel("Value");
          testData();
  
          return sbc;
      }
  
      public void testData()
      {
          HashMap&lt;String, Integer&gt; map = new HashMap&lt;&gt;();
  
          for (int i = 0; i &lt; (int) (Math.random() * 10); i++)
          {
              map.put("house" + i, (int) (Math.random() * 100));
          }
  
          createBarChartData(map);
      }
  
      public void createBarChartData(HashMap&lt;String, Integer&gt; map)
      {
          for (int i = 0; i &lt; map.size(); i++)
          {
              XYChart.Series&lt;String, Number&gt; series1 = new XYChart.Series&lt;&gt;();
              XYChart.Data&lt;String, Number&gt; dataS1 = new XYChart.Data&lt;&gt;();
  
              Integer get = map.get("house" + i);
              series1.setName(tcp);
              dataS1.setXValue(tcp);
              dataS1.setYValue(get);
              series1.getData().add(dataS1);
              xAxis.setCategories(FXCollections.&lt;String&gt;observableArrayList(Arrays.asList(tcp)));
              sbc.getData().clear();
              sbc.setData(FXCollections.&lt;XYChart.Series&lt;String, Number&gt;&gt;observableArrayList(Arrays.asList(series1)));
          }        
      }
  </code></pre>
  
  <p>But I get empty chart. In my case I want to refresh chart values every second with dynamic series of data. What would be the best way to do this with minimum resources?</p>