本文介绍了在POI代直线散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去创造与Apache POI散点图。但即时得到柔和的线条和它看起来像黑色条纹y轴的这么多值
这里是我的code。哪里是我的问题吗?是否有可能产生这样的POI图表?

  XSSFDrawing xlsx_drawing = my_worksheet.createDrawingPatriarch();
    XSSFClientAnchor锚= xlsx_drawing.createAnchor(0,0,0,0,X1,Y1,X2,Y2);
    / *创建基于锚点图表对象* /
    XSSFChart my_line_chart = xlsx_drawing.createChart(锚);    CTChart ctChart = my_line_chart.getCTChart();
    CTTitle标题= ctChart.addNewTitle();
    CTTx TX = title.addNewTx();
    CTTextBody丰富= tx.addNewRich();
    rich.addNewBodyPr(); //身体属性必须存在的,但可以是空
    CTTextParagraph第= rich.addNewP();
    CTRegularTextRun R = para.addNewR();
    r.setT(名)
    XSSFChartLegend传奇= my_line_chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.RIGHT);
    ScatterChartData数据= my_line_chart.getChartDataFactory()createScatterChartData()。
    ChartAxis bottomAxis = my_line_chart.getChartAxisFactory()createCategoryAxis(AxisPosition.BOTTOM)。
    XSSFValueAxis leftAxis = my_line_chart.getChartAxisFactory()createValueAxis(AxisPosition.LEFT)。
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
    ChartDataSource<数字与GT; XS = DataSources.fromNumericCellRange(my_worksheet,新的CellRangeAddress(titlesRow + 1,栏目,xrow,xrow));
    对于(字符串键:yrow.keySet()){
        ChartDataSource<数字与GT; YS1 = DataSources.fromNumericCellRange(my_worksheet,新的CellRangeAddress(titlesRow + 1,栏目,yrow.get(键),yrow.get(密钥)));
        ScatterChartSeries chartSerie = data.addSerie(XS,YS1);
        chartSerie.setTitle(键);
    }
    / *绘制图表与数据和图表轴* /输入
    my_line_chart.plot(数据,新ChartAxis [] {bottomAxis,leftAxis});


解决方案

所以,我发现,这增加图表用直线我要补充code

 为(CTScatterSer小号:my_line_chart.getCTChart()getPlotArea()getScatterChartArray(0).getSerArray()。){
        。s.addNewMarker()addNewSymbol()SETVAL(STMarkerStyle.NONE)。
        。s.addNewSmooth()SETVAL(假);
    }

Im trying to create scatter chart with apache poi. but im getting soft lines and so many values on y axis that it looks like black stripehere is my code. Where is my problem? Is it possible to generate such chart in poi?

    XSSFDrawing xlsx_drawing = my_worksheet.createDrawingPatriarch();
    XSSFClientAnchor anchor = xlsx_drawing.createAnchor(0, 0, 0, 0, x1, y1, x2, y2);
    /* Create the chart object based on the anchor point */
    XSSFChart my_line_chart = xlsx_drawing.createChart(anchor);

    CTChart ctChart = my_line_chart.getCTChart();
    CTTitle title = ctChart.addNewTitle();
    CTTx tx = title.addNewTx();
    CTTextBody rich = tx.addNewRich();
    rich.addNewBodyPr();  // body properties must exist, but can be empty
    CTTextParagraph para = rich.addNewP();
    CTRegularTextRun r = para.addNewR();
    r.setT(name)
    XSSFChartLegend legend = my_line_chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.RIGHT);     
    ScatterChartData data = my_line_chart.getChartDataFactory().createScatterChartData();     
    ChartAxis bottomAxis = my_line_chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
    XSSFValueAxis leftAxis = my_line_chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);     
    ChartDataSource<Number> xs = DataSources.fromNumericCellRange(my_worksheet, new CellRangeAddress(titlesRow+1, columns, xrow, xrow));
    for(String key: yrow.keySet()){
        ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(my_worksheet, new CellRangeAddress(titlesRow+1, columns, yrow.get(key), yrow.get(key)));
        ScatterChartSeries chartSerie = data.addSerie(xs, ys1);
        chartSerie.setTitle(key);
    }
    /* Plot the chart with the inputs from data and chart axis */
    my_line_chart.plot(data, new ChartAxis[] { bottomAxis, leftAxis });              
解决方案

So i found out, that to add chart with straight lines i should add code

  for(CTScatterSer s : my_line_chart.getCTChart().getPlotArea().getScatterChartArray(0).getSerArray()){
        s.addNewMarker().addNewSymbol().setVal(STMarkerStyle.NONE);
        s.addNewSmooth().setVal(false);
    }  

这篇关于在POI代直线散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 23:22