Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java POI折线图轴位置和其他问题_Java_Excel_Charts_Apache Poi - Fatal编程技术网

Java POI折线图轴位置和其他问题

Java POI折线图轴位置和其他问题,java,excel,charts,apache-poi,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();

我正在处理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)});

我无法打开我的xlsx文件(并且在尝试创建第二个值轴时):我收到了类似“不可读内容”的消息。有时excel会成功地重新绘制,并告诉我它在/xl/drawings/drawing1.xml中重新绘制了图形形状。我得到了这个错误:error062800_01.xml,但不熟悉xml

如果有人有什么想法

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