|
@@ -1,19 +1,40 @@
|
|
|
package com.lc.ibps.components.verification.excel;
|
|
package com.lc.ibps.components.verification.excel;
|
|
|
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Chart;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Drawing;
|
|
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
|
|
+import com.lc.ibps.components.verification.funcs.xValue;
|
|
|
|
|
+import com.lc.ibps.components.verification.model.InspectionItemVO;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.usermodel.charts.*;
|
|
import org.apache.poi.ss.usermodel.charts.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
|
|
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer;
|
|
|
|
|
-import org.openxmlformats.schemas.drawingml.x2006.chart.CTTrendline;
|
|
|
|
|
|
|
+import org.openxmlformats.schemas.drawingml.x2006.chart.*;
|
|
|
import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
|
|
import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
|
|
|
|
|
|
|
|
public class CreateExcelScatterChart {
|
|
public class CreateExcelScatterChart {
|
|
|
- public static void create(Sheet sheet) {
|
|
|
|
|
|
|
+ public static void create(Sheet sheet, InspectionItemVO item) {
|
|
|
|
|
|
|
|
|
|
+ Row row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
|
|
+ for (int i = 0; i < item.getItemCalcVO().getTargetValue().length; i++) {
|
|
|
|
|
+ final xValue value = item.getItemCalcVO().getTargetValue()[i];
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
|
|
|
+ cell.setCellValue(value.getDoub());
|
|
|
|
|
+ cell.setCellType(CellType.NUMERIC);
|
|
|
|
|
+ }
|
|
|
|
|
+ row.setZeroHeight(true);
|
|
|
|
|
+ int rowNum = row.getRowNum();
|
|
|
|
|
+
|
|
|
|
|
+ row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
|
|
+ for (int i = 0; i < item.getItemCalcVO().getSpecimensValue().length; i++) {
|
|
|
|
|
+ final xValue value = item.getItemCalcVO().getSpecimensValue()[i];
|
|
|
|
|
+ Cell cell = row.createCell(i);
|
|
|
|
|
+ cell.setCellValue(value.getDoub());
|
|
|
|
|
+ cell.setCellType(CellType.NUMERIC);
|
|
|
|
|
+ }
|
|
|
|
|
+ row.setZeroHeight(true);
|
|
|
|
|
+
|
|
|
|
|
+ row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
|
|
+ cell.setCellValue("线性回归图");
|
|
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
|
|
|
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
Drawing<?> drawing = sheet.createDrawingPatriarch();
|
|
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 16);
|
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, sheet.getLastRowNum() + 1, 6, sheet.getLastRowNum() + 16);
|
|
@@ -29,20 +50,28 @@ public class CreateExcelScatterChart {
|
|
|
|
|
|
|
|
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
|
|
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
|
|
|
bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
|
|
bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
|
|
|
- ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(8, 8, 2, 15));
|
|
|
|
|
- ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(7, 7, 2, 15));
|
|
|
|
|
|
|
+ ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum, rowNum, 0, item.getConfig().getSpecimensNum()-1));
|
|
|
|
|
+ ChartDataSource<Number> ys = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(rowNum+1, rowNum+1, 0, item.getConfig().getSpecimensNum()-1));
|
|
|
|
|
|
|
|
- ScatterChartSeries chartSerie = data.addSerie(xs, ys);
|
|
|
|
|
- chartSerie.setTitle("线性回归");
|
|
|
|
|
|
|
+ ScatterChartSeries chartSeries = data.addSerie(xs, ys);
|
|
|
|
|
+ chartSeries.setTitle("线性回归");
|
|
|
chart.plot(data, bottomAxis, leftAxis);
|
|
chart.plot(data, bottomAxis, leftAxis);
|
|
|
|
|
|
|
|
|
|
+ final CTChart ctChart = ((XSSFChart) chart).getCTChart();
|
|
|
|
|
+// ctChart.getLegend().getLegendPos().setVal(STLegendPos.B);
|
|
|
|
|
+ ctChart.unsetLegend();
|
|
|
|
|
+ ctChart.getPlotVisOnly().setVal(false);
|
|
|
//set line properties of first scatter chart data serie to no fill:
|
|
//set line properties of first scatter chart data serie to no fill:
|
|
|
- CTScatterSer[] scatterChartSeries = ((XSSFChart) chart).getCTChart().getPlotArea().getScatterChartArray(0).getSerArray();
|
|
|
|
|
|
|
+ CTScatterSer[] scatterChartSeries = ctChart.getPlotArea().getScatterChartArray(0).getSerArray();
|
|
|
for (int i = 0; i < scatterChartSeries.length; i++) {
|
|
for (int i = 0; i < scatterChartSeries.length; i++) {
|
|
|
scatterChartSeries[i].addNewSpPr().addNewLn().addNewNoFill();
|
|
scatterChartSeries[i].addNewSpPr().addNewLn().addNewNoFill();
|
|
|
- scatterChartSeries[i].addNewSmooth().setVal(true);
|
|
|
|
|
}
|
|
}
|
|
|
- final CTTrendline trendline = ((XSSFChart) chart).getCTChart().getPlotArea().getScatterChartArray(0).getSerArray(0)
|
|
|
|
|
|
|
+// ((XSSFChart) chart).getCTChart().getPlotArea().getScatterChartArray(0).getSerArray(0).getDPtList().
|
|
|
|
|
+
|
|
|
|
|
+ for(CTValAx ax: ctChart.getPlotArea().getValAxList()){
|
|
|
|
|
+ ax.addNewMajorGridlines();
|
|
|
|
|
+ }
|
|
|
|
|
+ final CTTrendline trendline = ctChart.getPlotArea().getScatterChartArray(0).getSerArray(0)
|
|
|
.addNewTrendline();
|
|
.addNewTrendline();
|
|
|
trendline.addNewDispRSqr().setVal(true);
|
|
trendline.addNewDispRSqr().setVal(true);
|
|
|
trendline.addNewIntercept().setVal(0.1767);
|
|
trendline.addNewIntercept().setVal(0.1767);
|