POI折线图轴位置等问题

时间:2016-04-06 10:07:53

标签: java excel charts apache-poi

我正在处理POI以创建图表,而且我遇到了一些问题。 首先,即使我改变AxisPosition,我总是在底部有x轴,在左边有y轴。其次我想有2个y轴。这是我的代码的一部分:

创建图表的功能:

private XSSFChart createChart(Sheet sheet,int[] anchors, String xLabel, String yLabel, String title){

    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = drawing.createAnchor(anchors[0], anchors[1], anchors[2],
 anchors[3], anchors[4], anchors[5], anchors[6], anchors[7] );
    XSSFChart chart = (XSSFChart) drawing.createChart(anchor);
    ChartLegend legend = chart.getOrCreateLegend();
    legend.setPosition(LegendPosition.TOP_RIGHT);
    ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.TOP);
    ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
    ValueAxis rightAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.RIGHT);
    leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
//Function to set axis title took from how-to-set-axis-labels-in-a-line-chart-using-apache-poi
    setValueAxisTitle(chart,0,yLabel);
    setValueAxisTitle(chart,0,"Second Axis");
    setCatAxisTitle(chart,0,xLabel);
    chart.setTitle(title);
    chart.getAxis();

    return chart;

}

绘制图表的代码

XSSFChart chart1=createChart(sheet,anchor1,"Temps","Courbes",title );
LineChartData dataM3s = chart1.getChartDataFactory().createLineChartData();
ChartDataSource<Number> yM3s = DataSources.fromNumericCellRange(sheet, 
    new CellRangeAddress(3, (numOfRows / numOfColumns) + 2, colToWrite, colToWrite));
LineChartSeries chartSeriesM3s =  dataM3s.addSeries(xs, yM3s);
chartSeriesM3s.setTitle(metric.getLibelle());
chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(1));
//By the way, this works as well:
//chart1.plot(dataM3s, new ChartAxis[] { chart1.getAxis().get(0), chart1.getAxis().get(1)});

当我改变

chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(1));

通过

chart1.plot(dataOther, chart1.getAxis().get(0), chart1.getAxis().get(2));

我无法打开我的xlsx文件(并且一旦尝试创建第二个值轴):我收到了类似于&#34;不可读内容的消息&#34;。有时excel suceed in reparing并告诉我它在/xl/drawings/drawing1.xml中修复了绘图形状。我收到此错误:error062800_01.xml但不熟悉XML。

如果有人有想法

0 个答案:

没有答案
相关问题