我试图用apache poi创建散点图。但我在y轴上得到柔和的线条和许多值,看起来像黑色条纹 这是我的代码。我的问题在哪里?是否有可能在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 });
答案 0 :(得分:0)
所以我发现,要添加直线图表我应该添加代码
for(CTScatterSer s : my_line_chart.getCTChart().getPlotArea().getScatterChartArray(0).getSerArray()){
s.addNewMarker().addNewSymbol().setVal(STMarkerStyle.NONE);
s.addNewSmooth().setVal(false);
}