title: Order of series in JFreeChart's StackedXYAreaChart
body: <p>In the example below, <em>Eden</em> is the series at index <code>0</code>, <em>Survivor</em> at index <code>1</code> and <em>Old</em> at index <code>2</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/HDyru.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HDyru.png" alt="Stacked Area Chart with 3 series"></a></p>
  
  <p>It the examle, <em>Old</em> is the top-most series in the chart, while <em>Eden</em> is at the bottom.</p>
  
  <p>What I would like to achieve is that <em>Eden</em> is the top-most series in the stacked chart, <em>Survivor</em> the one in the middle and <em>Old</em> on the bottom. Still, <em>Eden</em> should be the first entry in the legend and <em>Old</em> should be the last one.</p>
  
  <p>I currently use the following class to create my charts:</p>
  
  <pre><code>public class JFreeChartFactory {
      private static String fontName = "Palatino";
  
      private static Color[] chartSeriesColors = {
              new Color(0.0f, 1.0f, 0.0f, 0.9f),
              new Color(0.0f, 0.0f, 1.0f, 0.9f),
              new Color(1.0f, 0.0f, 0.0f, 0.9f),
              };
  
      public static JFreeChart createStackedXYAreaChart(String title, String subTitle, String xAxis, String yAxis, TableXYDataset dataset) {
  
          JFreeChart chart = ChartFactory.createStackedXYAreaChart(
                  title,
                  xAxis,
                  yAxis,
                  dataset);
  
          chart.getTitle().setFont(new Font(fontName, Font.BOLD, 18));
  
          if (subTitle != null) {
              chart.addSubtitle(new TextTitle(subTitle, new Font(fontName, Font.PLAIN, 14)));
          }
  
          XYPlot plot = (XYPlot) chart.getPlot();
          plot.setDomainPannable(true);
          plot.setRangePannable(true);
          plot.setDomainCrosshairVisible(true);
          plot.setRangeCrosshairVisible(true);
          plot.getDomainAxis().setLowerMargin(0.0);
          plot.getDomainAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
          plot.getDomainAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
          plot.getRangeAxis().setLabelFont(new Font(fontName, Font.BOLD, 14));
          plot.getRangeAxis().setTickLabelFont(new Font(fontName, Font.PLAIN, 12));
          chart.getLegend().setItemFont(new Font(fontName, Font.PLAIN, 14));
          chart.getLegend().setFrame(BlockBorder.NONE);
          chart.getLegend().setHorizontalAlignment(HorizontalAlignment.CENTER);
  
          for (int i = 0; i &lt; plot.getRendererCount(); i++) {
              XYItemRenderer renderer = plot.getRenderer(i);
              switch (renderer.getClass().getSimpleName()) {
                  case "StackedXYAreaRenderer2":
                      StackedXYAreaRenderer2 stackedRenderer = (StackedXYAreaRenderer2) renderer;
                      for (int cId = 0; cId &lt; chartSeriesColors.length; cId++) {
                          stackedRenderer.setSeriesPaint(cId, chartSeriesColors[cId]);
                      }
                      break;
              }
          }
  
          return chart;
      }
  }
  </code></pre>