title: JFreeChart: set line colors for XY Chart - 4 series, 2 datasets, dual axes
body: <p>I can't seem to set individual line colors for all four lines. When I use the lines:</p>
  
  <pre><code>plot.getRenderer().setSeriesPaint(0, new Color(0x00, 0xFF, 0x00));
  plot.getRenderer().setSeriesPaint(1, new Color(0x00, 0x00, 0x00));
  </code></pre>
  
  <p>(In the code below), it applies the first line to the FIRST series in BOTH datasets, and the second line to the SECOND series in BOTH datasets.</p>
  
  <p>How can I set a different color for all 4 lines?</p>
  
  <p>Thanks!</p>
  
  <pre><code>private JFreeChart createXYLineChart(String title) {
      XYDataset dataset1 = createXYVoltageDataset();
      XYDataset dataset2 = createXYCurrentDataset();
  
      JFreeChart chart = ChartFactory.createXYLineChart("Profile", "Set Current", "Voltage", null);
      XYPlot plot = (XYPlot) chart.getPlot(); 
      plot.setDataset(0, dataset1);
      plot.setDataset(1, dataset2);
  
      plot.setRangeAxis(1, new NumberAxis("Actual Current")); 
      plot.mapDatasetToRangeAxis(1, 1); //2nd dataset to 2nd y-axi
  
      plot.setBackgroundPaint(new Color(0xFF, 0xFF, 0xFF));
      plot.setDomainGridlinePaint(new Color(0x00, 0x00, 0xff));
      plot.setRangeGridlinePaint(new Color(0xff, 0x00, 0x00));
  
      plot.getRenderer().setSeriesPaint(0, new Color(0x00, 0xFF, 0x00));
      plot.getRenderer().setSeriesPaint(1, new Color(0x00, 0x00, 0x00));
      //plot.getRenderer().setSeriesPaint(2, new Color(0xFF, 0x00, 0x00)); // Does nothing
      //plot.getRenderer().setSeriesPaint(3, new Color(0x00, 0x00, 0xFF)); // Does nothing
      //plot.getRenderer(1).setSeriesPaint(3, new Color(0x00, 0x00, 0xFF)); // Null pointer exceptiopn
  
      return chart;
  }
  
  private  XYDataset createXYVoltageDataset() {
      final XYSeries s1 = new XYSeries("Min Voltage");
      final XYSeries s2 = new XYSeries("Max Voltage");
      for (int i = 0; i &lt; profile.getNumSteps(); i++) s1.add(i, profile.getStepMinVoltage(i));
      for (int i = 0; i &lt; profile.getNumSteps(); i++) s2.add(i, profile.getStepMaxVoltage(i));
      XYSeriesCollection dataset = new XYSeriesCollection();
      dataset.addSeries(s1);
      dataset.addSeries(s2);
      return dataset;
  }
  private  XYDataset createXYCurrentDataset() {
      final XYSeries s1 = new XYSeries("Min Current");
      final XYSeries s2 = new XYSeries("Max Current");
      for (int i = 0; i &lt; profile.getNumSteps(); i++){
          s1.add(i, profile.getStepMinCurrent(i));
      }
      for (int i = 0; i &lt; profile.getNumSteps(); i++) s2.add(i, profile.getStepMaxCurrent(i));
      XYSeriesCollection dataset = new XYSeriesCollection();
      dataset.addSeries(s1);
      dataset.addSeries(s2);
      return dataset;
  }
  </code></pre>