0

I want to get info like x, y, width, height, title of the chart. Here is my version for HSSFChart which works (It returns non-zero values):

HSSFChart chart
title = chart.getChartTitle();
x = chart.getChartX();
y = chart.getChartY();
width = chart.getChartWidth();
height = chart.getChartHeight();

The problem is that I can't get the same or any other info from XSSFChart.

XSSFDrawing drawing = sheet.createDrawingPatriarch();
List<XSSFChart> chartsList = drawing.getCharts();
for (XSSFChart chart : chartsList){

#ctChart

CTChart ctChart = chart.getCTChart();
CTPlotArea plotArea = ctChart.getPlotArea();
title = ctChart.getTitle.toString();

int size = plotArea.getScatterChartList().size();
    for (int j = 0; j < size; j++){
    List<CTScatterSer> seriesList = plotArea.getScatterChartList().get(j).getSerList();
    for (int i = 0; i < seriesList.size(); i++){
        CTScatterSer ser = seriesList.get(i);
       XmlObject serieX = ser.getXVal();
       XmlObject serieY = ser.getYVal();
       System.out.println("x: " + serieX.xmlText() + " y: " + serieY.xmlText());
    }
}
if (plotArea.getLayout() != null)
            if (plotArea.getLayout().getManualLayout() != null) 
                System.out.println("x: " + plotArea.getLayout().getManualLayout().getX() + " y: " + 
                        plotArea.getLayout().getManualLayout().getY());

#chart

chart.getManualLayout().getX();  // returns 0
chart.getManualLayout().getY();  // returns 0
chart.getManualLayout().getHeightRatio();  // returns 0.0
chart.getManualLayout().getWidthRatio();  // returns 0.0

It prints nothing even if there are many charts and series.

  • are all your variables empty from the beginning to the end of your script ? you can test that with the debugg mode and moving your mouse over some values. – GEnGEr Aug 21 '15 at 10:54
  • It was my bad. I used ScatterChart instead of LineChart class (in this case). Despite of that I still don't know how to get chart's x, y, width and height from XSSF. The code above keeps returning 0. For example: `chart.getManualLayout().getX();` – SzikakaPupu Aug 24 '15 at 10:28

1 Answers1

0

I am struggling with a similar problem, and I am stuck also in your code..

List<org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart> chartList=plotArea.getLineChartList();
int size = chartList.size();

Mine is a LineChart so I've changed accordingly, but I have this runtime error:

Exception in thread "main" java.lang.NoClassDefFoundError:    org/openxmlformats/schemas/drawingml/x2006/chart/impl/CTPlotAreaImpl$1LineChartList
at org.openxmlformats.schemas.drawingml.x2006.chart.impl.CTPlotAreaImpl.getLineChartList(Unknown Source)
at ....

Seems something is missing from my poi-openxml-schemas-3.13-20150929.jar file. Anyway, I've commented out the relevant part and I have NULL as a result of queries on ManualLayout. This is terrible.

I have a strong feeling that the Chart is not rendered in an XML file (as is XLSX) but it's only rendered where we open the file with Office (or OpenOffice), as if the layout is still not done and will be done by the GUI. In this case I think one can investigate this solution using PUNO:

http://www.wstech2.net/?do=0a,01,05

This involevs a bridge between Php and a running instance of OpenOffice, which exposes the UNO interface. I've looked at this but it seemed overly complicated to install, but maybe this is the only way.

zontar
  • 485
  • 7
  • 18