title: Second Line in an Apache-POI chart with seperate axis
body: <p>Hi this code taken from the answer <a href="https://stackoverflow.com/questions/55192804/how-do-i-add-a-second-line-with-a-second-axis-to-an-xddfchart-in-poi-4-0-1">here</a> is working as expected, but I want exactly the same Chart but in an Excel-Sheet</p>
  <pre><code>package eu.flexsolution.task.excel;
  
  import java.io.*;
  import org.apache.poi.xwpf.usermodel.*;
  import org.apache.poi.ss.util.CellRangeAddress;
  import org.apache.poi.util.Units;
  import org.apache.poi.xddf.usermodel.*;
  import org.apache.poi.xddf.usermodel.chart.*;
  
  public class TEst {
  
  public static void main(String[] args) throws Exception {
      try (XWPFDocument document = new XWPFDocument()) {
  
          // create the data
          String[] categories = new String[] { &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot; };
          Double[] values1 = new Double[] { 1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d };
          Double[] values2 = new Double[] { 200d, 300d, 400d, 500d, 600d, 700d, 800d, 900d, 1000d };
  
          // create the chart
          XWPFChart chart = document.createChart(15 * Units.EMU_PER_CENTIMETER, 10 * Units.EMU_PER_CENTIMETER);
  
          // create data sources
          int numOfPoints = categories.length;
          String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
          String valuesDataRange1 = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
          String valuesDataRange2 = chart.formatRange(new CellRangeAddress(1, numOfPoints, 2, 2));
          XDDFDataSource&lt;String&gt; categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
          XDDFNumericalDataSource&lt;Double&gt; valuesData1 = XDDFDataSourcesFactory.fromArray(values1, valuesDataRange1,
                  1);
          XDDFNumericalDataSource&lt;Double&gt; valuesData2 = XDDFDataSourcesFactory.fromArray(values2, valuesDataRange2,
                  2);
  
          // first line chart
          XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
          XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
          leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
          XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
          XDDFChartData.Series series = data.addSeries(categoriesData, valuesData1);
          chart.plot(data);
  
          solidLineSeries(data, 0, PresetColor.BLUE);
  
          // second line chart
          // bottom axis must be there but must not be visible
          bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
          bottomAxis.setVisible(false);
  
          XDDFValueAxis rightAxis = chart.createValueAxis(AxisPosition.RIGHT);
          rightAxis.setCrosses(AxisCrosses.MAX);
  
          // set correct cross axis
          bottomAxis.crossAxis(rightAxis);
          rightAxis.crossAxis(bottomAxis);
  
          data = chart.createData(ChartTypes.LINE, bottomAxis, rightAxis);
          series = data.addSeries(categoriesData, valuesData2);
          chart.plot(data);
  
          // correct the id and order, must not be 0 again because there is one line
          // series already
          chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getIdx().setVal(1);
          chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getOrder().setVal(1);
  
          solidLineSeries(data, 0, PresetColor.RED);
  
          // Write the output to a file
          try (FileOutputStream fileOut = new FileOutputStream(&quot;CreateWordXDDFChart.docx&quot;)) {
              document.write(fileOut);
          }
      }
  }
  
  private static void solidLineSeries(XDDFChartData data, int index, PresetColor color) {
      XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(color));
      XDDFLineProperties line = new XDDFLineProperties();
      line.setFillProperties(fill);
      XDDFChartData.Series series = data.getSeries().get(index);
      XDDFShapeProperties properties = series.getShapeProperties();
      if (properties == null) {
          properties = new XDDFShapeProperties();
      }
      properties.setLineProperties(line);
      series.setShapeProperties(properties);
  }
  }
  </code></pre>
  <p>So I modified the code like this to get an XLSX document, but the Chart isn't the same
  <a href="https://i.stack.imgur.com/NhKPI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NhKPI.png" alt="chart in excel" /></a></p>
  <pre><code>package eu.flexsolution.task.excel;
  
  
  import java.io.*;
  
  import org.apache.poi.xwpf.usermodel.*;
  
  import org.apache.poi.ss.util.CellRangeAddress;
  import org.apache.poi.util.Units;
  
  import org.apache.poi.xddf.usermodel.*;
  import org.apache.poi.xddf.usermodel.chart.*;
  import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
  import org.apache.poi.xssf.usermodel.XSSFDrawing;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
  public class TEst {
  
  
  public static void main(String[] args) throws Exception {
      try (XSSFWorkbook document = new XSSFWorkbook()) {
          XSSFSheet chartSheet = document.createSheet(&quot;chart&quot;);
          
          // create the data
          String[] categories = new String[] { &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot; };
          Double[] values1 = new Double[] { 1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d };
          Double[] values2 = new Double[] { 200d, 300d, 400d, 500d, 600d, 700d, 800d, 900d, 1000d };
  
          // create the chart
          XSSFDrawing drawing = chartSheet.createDrawingPatriarch();
          XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 0, 26, 40);
          XDDFChart chart = drawing.createChart(anchor);
          
          // create data sources
          int numOfPoints = categories.length;
          String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
          String valuesDataRange1 = chart.formatRange(new CellRangeAddress(1, numOfPoints, 1, 1));
          String valuesDataRange2 = chart.formatRange(new CellRangeAddress(1, numOfPoints, 2, 2));
          XDDFDataSource&lt;String&gt; categoriesData = XDDFDataSourcesFactory.fromArray(categories, categoryDataRange, 0);
          XDDFNumericalDataSource&lt;Double&gt; valuesData1 = XDDFDataSourcesFactory.fromArray(values1, valuesDataRange1,
                  1);
          XDDFNumericalDataSource&lt;Double&gt; valuesData2 = XDDFDataSourcesFactory.fromArray(values2, valuesDataRange2,
                  2);
  
          // first line chart
          XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
          XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
          leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
          XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
          XDDFChartData.Series series = data.addSeries(categoriesData, valuesData1);
          chart.plot(data);
  
          solidLineSeries(data, 0, PresetColor.BLUE);
  
          // second line chart
          // bottom axis must be there but must not be visible
          bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
          bottomAxis.setVisible(false);
  
          XDDFValueAxis rightAxis = chart.createValueAxis(AxisPosition.RIGHT);
          rightAxis.setCrosses(AxisCrosses.MAX);
  
          // set correct cross axis
          bottomAxis.crossAxis(rightAxis);
          rightAxis.crossAxis(bottomAxis);
  
          data = chart.createData(ChartTypes.LINE, bottomAxis, rightAxis);
          series = data.addSeries(categoriesData, valuesData2);
          chart.plot(data);
  
          // correct the id and order, must not be 0 again because there is one line
          // series already
          chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getIdx().setVal(1);
          chart.getCTChart().getPlotArea().getLineChartArray(1).getSerArray(0).getOrder().setVal(1);
  
          solidLineSeries(data, 0, PresetColor.RED);
  
          // Write the output to a file
          try (FileOutputStream fileOut = new FileOutputStream(&quot;CreateWordXDDFChart.xlsx&quot;)) {
              document.write(fileOut);
          }
      }
  }
  
  private static void solidLineSeries(XDDFChartData data, int index, PresetColor color) {
      XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(color));
      XDDFLineProperties line = new XDDFLineProperties();
      line.setFillProperties(fill);
      XDDFChartData.Series series = data.getSeries().get(index);
      XDDFShapeProperties properties = series.getShapeProperties();
      if (properties == null) {
          properties = new XDDFShapeProperties();
      }
      properties.setLineProperties(line);
      series.setShapeProperties(properties);
  }
  }
  </code></pre>