title: JfreeChart - How to hide item from legend - Problem of colors
body: <p>I would like to hide items from legend in Jfreechart and I've tried this code 
  <a href="https://stackoverflow.com/questions/3342406/jfreechart-how-to-hide-items-from-legend/3342965#3342965">jFreeChart: How to hide items from legend?</a></p>
  
  <p>It works but something strange happened : the colors of the legend items do not match to the right data anymore. In other words, in the graph, a piece of data appears in yellow for example but the legend corresponding to this item appears in another color. In fact, the colors in the legend have been mixed.</p>
  
  <p>Besides, when I try to display both old and new legends, there is no problem of colors but when I make the old legend invisible, the problem of mixed color appears. Obviously, I would like not to display the old legend.</p>
  
  <p>Working code =></p>
  
  <pre><code>LegendItemCollection legendItemsOld = localCombinedDomainXYPlot.getLegendItems();
  final LegendItemCollection legendItemsNew = new LegendItemCollection();
  
  for(int i = 0; i&lt;4; i++){
      legendItemsNew.add(legendItemsOld.get(i));
  }
  LegendItemSource source = new LegendItemSource() {
      LegendItemCollection lic = new LegendItemCollection();
      {lic.addAll(legendItemsNew);}
      public LegendItemCollection getLegendItems() {  
          return lic;
      }
  };
  localJFreeChart.addLegend(new LegendTitle(source));
  
  ChartUtilities.applyCurrentTheme(localJFreeChart);
  localJFreeChart.getLegend().setVisible(true); ///////////////////
  </code></pre>
  
  <p>Not working code =></p>
  
  <pre><code>LegendItemCollection legendItemsOld = localCombinedDomainXYPlot.getLegendItems();
  final LegendItemCollection legendItemsNew = new LegendItemCollection();
  
  for(int i = 0; i&lt;4; i++){
      legendItemsNew.add(legendItemsOld.get(i));
  }
  LegendItemSource source = new LegendItemSource() {
      LegendItemCollection lic = new LegendItemCollection();
      {lic.addAll(legendItemsNew);}
      public LegendItemCollection getLegendItems() {  
          return lic;
      }
  };
  localJFreeChart.addLegend(new LegendTitle(source));
  
  ChartUtilities.applyCurrentTheme(localJFreeChart);
  localJFreeChart.getLegend().setVisible(false); ///////////////////
  </code></pre>