2016-09-22 6 views
2

꺾은 선형 차트가있는 Excel 파일을 만듭니다. 차트를 작성하고 데이터로 채웠지 만 차트에 포인트를 만들 수는 없습니다. 누구든지 알고 있나요, 내가이 포인트 (삼각형, 사각형, 동그라미 등) 차트에서 아파치 poi를 사용하여 생성 할 수있는 방법이 무엇입니까?Apache poi Excel 라인 차트 포인트

enter image description here

이 현재의 문자를 생성하는 내 코드입니다 :

public static void main(String[] args) throws Exception { 
     Workbook wb = new XSSFWorkbook(); 
     Sheet dataSheet = wb.createSheet("linechart"); 

     final int NUM_OF_ROWS = 10; 
     final int NUM_OF_COLUMNS = 4; 

     Row row; 
     Cell cell; 
     for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) { 
      row = dataSheet.createRow((short) rowIndex); 
      for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) { 
       cell = row.createCell((short) colIndex); 
       cell.setCellValue(rowIndex * ((colIndex + 1) + ((int) (Math.random() * 10)))); 
      } 
     } 

     Drawing drawing = dataSheet.createDrawingPatriarch(); 
     ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, NUM_OF_COLUMNS + 2, 3, NUM_OF_COLUMNS + 15, 20); 

     Chart chart = drawing.createChart(anchor); 
     ChartLegend legend = chart.getOrCreateLegend(); 
     legend.setPosition(LegendPosition.RIGHT); 

     LineChartData data = chart.getChartDataFactory().createLineChartData(); 

     ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM); 
     ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); 
     leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); 

     ChartDataSource<Number> xs = DataSources.fromNumericCellRange(dataSheet, new CellRangeAddress(0, NUM_OF_ROWS - 1, 0, 0)); 
     ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(dataSheet, new CellRangeAddress(0, NUM_OF_ROWS - 1, 1, 1)); 
     ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(dataSheet, new CellRangeAddress(0, NUM_OF_ROWS - 1, 2, 2)); 
     ChartDataSource<Number> ys3 = DataSources.fromNumericCellRange(dataSheet, new CellRangeAddress(0, NUM_OF_ROWS - 1, 3, 3)); 

     LineChartSeries series1 = data.addSeries(xs, ys1); 
     series1.setTitle("one"); 
     LineChartSeries series2 = data.addSeries(xs, ys2); 
     series2.setTitle("two"); 
     LineChartSeries series3 = data.addSeries(xs, ys3); 
     series3.setTitle("three"); 

     chart.plot(data, bottomAxis, leftAxis); 

     XSSFChart xssfChart = (XSSFChart) chart; 
     CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea(); 
     plotArea.getLineChartArray()[0].getSmooth(); 
     CTBoolean ctBool = CTBoolean.Factory.newInstance(); 
     ctBool.setVal(false); 
     plotArea.getLineChartArray()[0].setSmooth(ctBool); 
     for (CTLineSer ser : plotArea.getLineChartArray()[0].getSerArray()) { 
      ser.setSmooth(ctBool); 
     } 

     FileOutputStream fileOut = new FileOutputStream("chart.xlsx"); 
     wb.write(fileOut); 
     fileOut.close(); 
    } 

답변

2

솔루션 :

CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea(); 
CTMarker ctMarker = CTMarker.Factory.newInstance(); 
ctMarker.setSymbol(CTMarkerStyle.Factory.newInstance()); 
for (CTLineSer ser : plotArea.getLineChartArray()[0].getSerArray()) { 
    ser.setMarker(ctMarker); 
} 
0

다음 코드는 당신이

CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea(); 
    plotArea.getLineChartArray()[0].getSmooth(); 
    CTMarker ctMarker = CTMarker.Factory.newInstance(); 
    ctMarker.setSymbol(CTMarkerStyle.Factory.newInstance()); 
    CTBoolean ctBool = CTBoolean.Factory.newInstance(); 
    ctBool.setVal(false); 
    plotArea.getLineChartArray()[0].setSmooth(ctBool); 
    for (CTLineSer ser : plotArea.getLineChartArray()[0].getSerArray()) { 
     ser.setSmooth(ctBool); 
     ser.setMarker(ctMarker); 
    } 
찾고 정확히 무엇을 줄 것이다