0

I've generated a graph using Apache POI. I got the graphs correctly but in the border line, the corners are round. I need to change them to normal sharp corners. how can I do that? my code is as follows. (I've posted only the code for border line since the code is too long. If anybody needs the full code, please comment)

XSSFSheet sheet4 = wb.createSheet("Graph");
        Drawing<?> drawing = sheet4.createDrawingPatriarch();
        ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 17, 27);

        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(sheet1, new CellRangeAddress(2, m-1, 0, 0));
        ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, m-1, 1, 1));
        ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, m-1, 3, 3));
        ChartDataSource<Number> ys3 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, m-1, 4, 4));
        ChartDataSource<Number> ys4 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, m-1, 8, 8));

        LineChartSeries series1 = data.addSeries(xs, ys1);
        series1.setTitle("VAL1");
        LineChartSeries series2 = data.addSeries(xs, ys2);
        series2.setTitle("VAL2");
        LineChartSeries series3 = data.addSeries(xs, ys3);
        series3.setTitle("VAL3");
        LineChartSeries series4 = data.addSeries(xs, ys4);
        series4.setTitle("VAL4");

        chart.plot(data, bottomAxis, leftAxis);

        if (chart instanceof XSSFChart) { 


        XSSFChart xchart = (XSSFChart) chart;
        CTChart ctChart = xchart.getCTChart();
        CTTitle title = ctChart.addNewTitle();
        CTTx tx = title.addNewTx();
        CTTextBody rich = tx.addNewRich();
        rich.addNewBodyPr(); 
        CTTextParagraph para = rich.addNewP();
        CTRegularTextRun r = para.addNewR();
        r.setT("TITLE");
            }


        if (chart instanceof XSSFChart) { 
        XSSFChart xssfChart = (XSSFChart)chart;

       //Plot area background and border line
       if (xssfChart.getCTChartSpace().getSpPr() == null) xssfChart.getCTChartSpace().addNewSpPr();
       if (xssfChart.getCTChartSpace().getSpPr().getSolidFill() == null) 
        xssfChart.getCTChartSpace().getSpPr().addNewSolidFill();
       if (xssfChart.getCTChartSpace().getSpPr().getSolidFill().getSrgbClr() == null)
        xssfChart.getCTChartSpace().getSpPr().getSolidFill().addNewSrgbClr();
       xssfChart.getCTChartSpace().getSpPr().getSolidFill().getSrgbClr().setVal(new byte[]{(byte)255,(byte)255,(byte)255});
       if (xssfChart.getCTChartSpace().getSpPr().getLn() == null) xssfChart.getCTChartSpace().getSpPr().addNewLn();
       xssfChart.getCTChartSpace().getSpPr().getLn().setW(Units.pixelToEMU(0));
       if (xssfChart.getCTChartSpace().getSpPr().getLn().getSolidFill() == null)
        xssfChart.getCTChartSpace().getSpPr().getLn().addNewSolidFill();
       if (xssfChart.getCTChartSpace().getSpPr().getLn().getSolidFill().getSrgbClr() == null)
        xssfChart.getCTChartSpace().getSpPr().getLn().getSolidFill().addNewSrgbClr();
       xssfChart.getCTChartSpace().getSpPr().getLn().getSolidFill().getSrgbClr().setVal(new byte[]{(byte)0,(byte)0,(byte)0});

    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);
           }
LSH94
  • 109
  • 1
  • 9
  • 2
    https://stackoverflow.com/questions/44255527/changing-the-shape-of-chart-generated-by-apache-poi-for-excel-sheet/44265659#44265659 – Axel Richter Aug 09 '18 at 06:16
  • 2
    Possible duplicate of [Changing the shape of chart generated by apache poi for excel sheet](https://stackoverflow.com/questions/44255527/changing-the-shape-of-chart-generated-by-apache-poi-for-excel-sheet) – Sankumarsingh Aug 13 '18 at 07:28

0 Answers0