Bugzilla 51196: Initial support for Spreadsheet Chart API
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1125275 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f90fcee530
commit
0d3bce27a2
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta3" date="2011-??-??">
|
<release version="3.8-beta3" date="2011-??-??">
|
||||||
|
<action dev="poi-developers" type="add">51196 - Initial support for Spreadsheet Chart API</action>
|
||||||
<action dev="poi-developers" type="add">Add support for OOXML Agile Encryption</action>
|
<action dev="poi-developers" type="add">Add support for OOXML Agile Encryption</action>
|
||||||
<action dev="poi-developers" type="add">51160 - Initial version of SXSSF, a low memory foortprint API to produce xlsx files</action>
|
<action dev="poi-developers" type="add">51160 - Initial version of SXSSF, a low memory foortprint API to produce xlsx files</action>
|
||||||
<action dev="poi-developers" type="fix">51171 - Improved performance of opening large .xls files</action>
|
<action dev="poi-developers" type="fix">51171 - Improved performance of opening large .xls files</action>
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.examples;
|
||||||
|
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.*;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Illustrates how to create a simple scatter chart.
|
||||||
|
*/
|
||||||
|
public class ScatterChart {
|
||||||
|
|
||||||
|
public static void main(String[]args) throws Exception {
|
||||||
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
CreationHelper creationHelper = wb.getCreationHelper();
|
||||||
|
Sheet sheet = wb.createSheet("new sheet");
|
||||||
|
final int NUM_OF_ROWS = 3;
|
||||||
|
final int NUM_OF_COLUMNS = 10;
|
||||||
|
|
||||||
|
// Create a row and put some cells in it. Rows are 0 based.
|
||||||
|
Row row;
|
||||||
|
Cell cell;
|
||||||
|
for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {
|
||||||
|
row = sheet.createRow((short)rowIndex);
|
||||||
|
for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {
|
||||||
|
cell = row.createCell((short)colIndex);
|
||||||
|
cell.setCellValue(colIndex * (rowIndex + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Drawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);
|
||||||
|
|
||||||
|
Chart chart = drawing.createChart(anchor);
|
||||||
|
ChartLegend legend = chart.getOrCreateLegend();
|
||||||
|
legend.setPosition(LegendPosition.RIGHT);
|
||||||
|
|
||||||
|
ScatterChartData data = chart.getChartDataFactory().createScatterChartData();
|
||||||
|
|
||||||
|
ValueAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
|
||||||
|
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
|
||||||
|
|
||||||
|
ScatterChartSerie firstSerie = data.addSerie();
|
||||||
|
firstSerie.setXValues(sheet, new CellRangeAddress(0, 0, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
|
||||||
|
firstSerie.setYValues(sheet, new CellRangeAddress(1, 1, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
|
||||||
|
|
||||||
|
ScatterChartSerie secondSerie = data.addSerie();
|
||||||
|
secondSerie.setXValues(sheet, new CellRangeAddress(0, 0, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
|
||||||
|
secondSerie.setYValues(sheet, new CellRangeAddress(2, 2, NUM_OF_COLUMNS + 1, NUM_OF_COLUMNS + 1));
|
||||||
|
|
||||||
|
chart.plot(data, bottomAxis, leftAxis);
|
||||||
|
|
||||||
|
// Write the output to a file
|
||||||
|
FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx");
|
||||||
|
wb.write(fileOut);
|
||||||
|
fileOut.close();
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ import org.apache.poi.ddf.EscherComplexProperty;
|
|||||||
import org.apache.poi.ddf.EscherOptRecord;
|
import org.apache.poi.ddf.EscherOptRecord;
|
||||||
import org.apache.poi.ddf.EscherProperty;
|
import org.apache.poi.ddf.EscherProperty;
|
||||||
import org.apache.poi.hssf.record.EscherAggregate;
|
import org.apache.poi.hssf.record.EscherAggregate;
|
||||||
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
import org.apache.poi.util.StringUtil;
|
import org.apache.poi.util.StringUtil;
|
||||||
import org.apache.poi.ss.usermodel.Drawing;
|
import org.apache.poi.ss.usermodel.Drawing;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||||
@ -160,7 +161,7 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
|
|||||||
/**
|
/**
|
||||||
* YK: used to create autofilters
|
* YK: used to create autofilters
|
||||||
*
|
*
|
||||||
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setAutoFilter(int, int, int, int)
|
* @see org.apache.poi.hssf.usermodel.HSSFSheet#setAutoFilter(org.apache.poi.ss.util.CellRangeAddress)
|
||||||
*/
|
*/
|
||||||
HSSFSimpleShape createComboBox(HSSFAnchor anchor)
|
HSSFSimpleShape createComboBox(HSSFAnchor anchor)
|
||||||
{
|
{
|
||||||
@ -276,4 +277,27 @@ public final class HSSFPatriarch implements HSSFShapeContainer, Drawing {
|
|||||||
protected EscherAggregate _getBoundAggregate() {
|
protected EscherAggregate _getBoundAggregate() {
|
||||||
return _boundAggregate;
|
return _boundAggregate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new client anchor and sets the top-left and bottom-right
|
||||||
|
* coordinates of the anchor.
|
||||||
|
*
|
||||||
|
* @param dx1 the x coordinate in EMU within the first cell.
|
||||||
|
* @param dy1 the y coordinate in EMU within the first cell.
|
||||||
|
* @param dx2 the x coordinate in EMU within the second cell.
|
||||||
|
* @param dy2 the y coordinate in EMU within the second cell.
|
||||||
|
* @param col1 the column (0 based) of the first cell.
|
||||||
|
* @param row1 the row (0 based) of the first cell.
|
||||||
|
* @param col2 the column (0 based) of the second cell.
|
||||||
|
* @param row2 the row (0 based) of the second cell.
|
||||||
|
* @return the newly created client anchor
|
||||||
|
*/
|
||||||
|
public HSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2){
|
||||||
|
return new HSSFClientAnchor(dx1, dy1, dx2, dy2, (short)col1, row1, (short)col2, row2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chart createChart(ClientAnchor anchor) {
|
||||||
|
throw new RuntimeException("NotImplemented");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
66
src/java/org/apache/poi/ss/usermodel/Chart.java
Normal file
66
src/java/org/apache/poi/ss/usermodel/Chart.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartData;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartLegend;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* High level representation of a chart.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface Chart {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an appropriate ChartDataFactory implementation
|
||||||
|
*/
|
||||||
|
ChartDataFactory getChartDataFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an appropriate ChartAxisFactory implementation
|
||||||
|
*/
|
||||||
|
ChartAxisFactory getChartAxisFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return chart legend instance
|
||||||
|
*/
|
||||||
|
ChartLegend getOrCreateLegend();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete current chart legend.
|
||||||
|
*/
|
||||||
|
void deleteLegend();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of all chart axis
|
||||||
|
*/
|
||||||
|
List<? extends ChartAxis> getAxis();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plots specified data on the chart.
|
||||||
|
*
|
||||||
|
* @param data a data to plot
|
||||||
|
*/
|
||||||
|
void plot(ChartData data, ChartAxis... axis);
|
||||||
|
}
|
@ -17,10 +17,51 @@
|
|||||||
package org.apache.poi.ss.usermodel;
|
package org.apache.poi.ss.usermodel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* High level representation of spreadsheet drawing.
|
||||||
* @author Yegor Kozlov
|
* @author Yegor Kozlov
|
||||||
|
* @author Roman Kashitsyn
|
||||||
*/
|
*/
|
||||||
public interface Drawing {
|
public interface Drawing {
|
||||||
|
/**
|
||||||
|
* Creates a picture.
|
||||||
|
* @param anchor the client anchor describes how this picture is
|
||||||
|
* attached to the sheet.
|
||||||
|
* @param pictureIndex the index of the picture in the workbook collection
|
||||||
|
* of pictures.
|
||||||
|
*
|
||||||
|
* @return the newly created picture.
|
||||||
|
*/
|
||||||
Picture createPicture(ClientAnchor anchor, int pictureIndex);
|
Picture createPicture(ClientAnchor anchor, int pictureIndex);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a comment.
|
||||||
|
* @param anchor the client anchor describes how this comment is attached
|
||||||
|
* to the sheet.
|
||||||
|
* @return the newly created comment.
|
||||||
|
*/
|
||||||
Comment createCellComment(ClientAnchor anchor);
|
Comment createCellComment(ClientAnchor anchor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a chart.
|
||||||
|
* @param anchor the client anchor describes how this chart is attached to
|
||||||
|
* the sheet.
|
||||||
|
* @return the newly created chart
|
||||||
|
*/
|
||||||
|
Chart createChart(ClientAnchor anchor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new client anchor and sets the top-left and bottom-right
|
||||||
|
* coordinates of the anchor.
|
||||||
|
*
|
||||||
|
* @param dx1 the x coordinate in EMU within the first cell.
|
||||||
|
* @param dy1 the y coordinate in EMU within the first cell.
|
||||||
|
* @param dx2 the x coordinate in EMU within the second cell.
|
||||||
|
* @param dy2 the y coordinate in EMU within the second cell.
|
||||||
|
* @param col1 the column (0 based) of the first cell.
|
||||||
|
* @param row1 the row (0 based) of the first cell.
|
||||||
|
* @param col2 the column (0 based) of the second cell.
|
||||||
|
* @param row2 the row (0 based) of the second cell.
|
||||||
|
* @return the newly created client anchor
|
||||||
|
*/
|
||||||
|
ClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the possible crossing states of an axis.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public enum AxisCrossBetween {
|
||||||
|
/**
|
||||||
|
* Specifies the value axis shall cross the category axis
|
||||||
|
* between data markers.
|
||||||
|
*/
|
||||||
|
BETWEEN,
|
||||||
|
/**
|
||||||
|
* Specifies the value axis shall cross the category axis at
|
||||||
|
* the midpoint of a category.
|
||||||
|
*/
|
||||||
|
MIDPOINT_CATEGORY
|
||||||
|
}
|
40
src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java
Normal file
40
src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the possible crossing points for an axis.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public enum AxisCrosses {
|
||||||
|
/**
|
||||||
|
* The category axis crosses at the zero point of the value axis (if
|
||||||
|
* possible), or the minimum value (if the minimum is greater than zero) or
|
||||||
|
* the maximum (if the maximum is less than zero).
|
||||||
|
*/
|
||||||
|
AUTO_ZERO,
|
||||||
|
/**
|
||||||
|
* The axis crosses at the maximum value.
|
||||||
|
*/
|
||||||
|
MIN,
|
||||||
|
/**
|
||||||
|
* Axis crosses at the minimum value of the chart.
|
||||||
|
*/
|
||||||
|
MAX
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the possible ways to place a picture on a data point, series, wall, or floor.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public enum AxisOrientation {
|
||||||
|
/**
|
||||||
|
* Specifies that the values on the axis shall be reversed
|
||||||
|
* so they go from maximum to minimum.
|
||||||
|
*/
|
||||||
|
MAX_MIN,
|
||||||
|
/**
|
||||||
|
* Specifies that the axis values shall be in the usual
|
||||||
|
* order, minimum to maximum.
|
||||||
|
*/
|
||||||
|
MIN_MAX
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of all possible axis positions.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public enum AxisPosition {
|
||||||
|
BOTTOM,
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
TOP
|
||||||
|
}
|
123
src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java
Normal file
123
src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* High level representation of chart axis.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ChartAxis {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis id
|
||||||
|
*/
|
||||||
|
long getId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis position
|
||||||
|
*/
|
||||||
|
AxisPosition getPosition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position new axis position
|
||||||
|
*/
|
||||||
|
void setPosition(AxisPosition position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis number format
|
||||||
|
*/
|
||||||
|
String getNumberFormat();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param format axis number format
|
||||||
|
*/
|
||||||
|
void setNumberFormat(String format);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if log base is defined, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isSetLogBase();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param logBase a number between 2 and 1000 (inclusive)
|
||||||
|
* @throws IllegalArgumentException if log base not within allowed range
|
||||||
|
*/
|
||||||
|
void setLogBase(double logBase);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis log base or 0.0 if not set
|
||||||
|
*/
|
||||||
|
double getLogBase();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if minimum value is defined, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isSetMinimum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis minimum or 0.0 if not set
|
||||||
|
*/
|
||||||
|
double getMinimum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param min axis minimum
|
||||||
|
*/
|
||||||
|
void setMinimum(double min);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if maximum value is defined, false otherwise
|
||||||
|
*/
|
||||||
|
boolean isSetMaximum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis maximum or 0.0 if not set
|
||||||
|
*/
|
||||||
|
double getMaximum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param max axis maximum
|
||||||
|
*/
|
||||||
|
void setMaximum(double max);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis orientation
|
||||||
|
*/
|
||||||
|
AxisOrientation getOrientation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param axis orientation
|
||||||
|
*/
|
||||||
|
void setOrientation(AxisOrientation orientation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param crosses axis cross type
|
||||||
|
*/
|
||||||
|
void setCrosses(AxisCrosses crosses);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return axis cross type
|
||||||
|
*/
|
||||||
|
AxisCrosses getCrosses();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declare this axis cross another axis.
|
||||||
|
* @param axis that this axis should cross
|
||||||
|
*/
|
||||||
|
void crossAxis(ChartAxis axis);
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory for different chart axis.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ChartAxisFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return new value axis
|
||||||
|
*/
|
||||||
|
ValueAxis createValueAxis(AxisPosition pos);
|
||||||
|
|
||||||
|
}
|
36
src/java/org/apache/poi/ss/usermodel/charts/ChartData.java
Normal file
36
src/java/org/apache/poi/ss/usermodel/charts/ChartData.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A base for all chart data types.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ChartData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fills a chart with data specified by implementation.
|
||||||
|
*
|
||||||
|
* @param chart a chart to fill in
|
||||||
|
* @param axis chart axis to use
|
||||||
|
*/
|
||||||
|
void fillChart(Chart chart, ChartAxis... axis);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory for different chart data types.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ChartDataFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return an appropriate ScatterChartData instance
|
||||||
|
*/
|
||||||
|
ScatterChartData createScatterChartData();
|
||||||
|
|
||||||
|
}
|
37
src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java
Normal file
37
src/java/org/apache/poi/ss/usermodel/charts/ChartLegend.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* High level representation of chart legend.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ChartLegend {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return legend position
|
||||||
|
*/
|
||||||
|
LegendPosition getPosition();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param position new legend position
|
||||||
|
*/
|
||||||
|
void setPosition(LegendPosition position);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration of all possible chart legend positions.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public enum LegendPosition {
|
||||||
|
BOTTOM,
|
||||||
|
LEFT,
|
||||||
|
RIGHT,
|
||||||
|
TOP,
|
||||||
|
TOP_RIGHT
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ScatterChartData extends ChartData {
|
||||||
|
/**
|
||||||
|
* @return a new scatter chart serie
|
||||||
|
*/
|
||||||
|
ScatterChartSerie addSerie();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of all series
|
||||||
|
*/
|
||||||
|
List<? extends ScatterChartSerie> getSeries();
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ScatterChartSerie {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sheet a sheet to take range from
|
||||||
|
* @param address a column or a row with values
|
||||||
|
*/
|
||||||
|
void setXValues(Sheet sheet, CellRangeAddress address);
|
||||||
|
|
||||||
|
/**'
|
||||||
|
* @param sheet a sheet to take range from
|
||||||
|
* @param address a column or a row with values
|
||||||
|
*/
|
||||||
|
void setYValues(Sheet sheet, CellRangeAddress address);
|
||||||
|
|
||||||
|
}
|
34
src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java
Normal file
34
src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.ss.usermodel.charts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public interface ValueAxis extends ChartAxis {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return cross between type
|
||||||
|
*/
|
||||||
|
AxisCrossBetween getCrossBetween();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param crossBetween cross between type
|
||||||
|
*/
|
||||||
|
void setCrossBetween(AxisCrossBetween crossBetween);
|
||||||
|
}
|
@ -80,10 +80,24 @@ public class CellRangeAddress extends CellRangeAddressBase {
|
|||||||
* like single cell references (e.g. 'A1' instead of 'A1:A1').
|
* like single cell references (e.g. 'A1' instead of 'A1:A1').
|
||||||
*/
|
*/
|
||||||
public String formatAsString() {
|
public String formatAsString() {
|
||||||
|
return formatAsString(null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the text format of this range using specified sheet name.
|
||||||
|
*/
|
||||||
|
public String formatAsString(String sheetName, boolean useAbsoluteAddress) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn());
|
if (sheetName != null) {
|
||||||
CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn());
|
sb.append(sheetName);
|
||||||
|
sb.append("!");
|
||||||
|
}
|
||||||
|
CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn(),
|
||||||
|
useAbsoluteAddress, useAbsoluteAddress);
|
||||||
|
CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn(),
|
||||||
|
useAbsoluteAddress, useAbsoluteAddress);
|
||||||
sb.append(cellRefFrom.formatAsString());
|
sb.append(cellRefFrom.formatAsString());
|
||||||
|
|
||||||
//for a single-cell reference return A1 instead of A1:A1
|
//for a single-cell reference return A1 instead of A1:A1
|
||||||
if(!cellRefFrom.equals(cellRefTo)){
|
if(!cellRefFrom.equals(cellRefTo)){
|
||||||
sb.append(':');
|
sb.append(':');
|
||||||
|
@ -21,11 +21,24 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxisFactory;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartAxis;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFValueAxis;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartLegend;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartData;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisPosition;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
@ -33,14 +46,29 @@ import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChartSpace;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
|
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLayout;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTManualLayout;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPrintSettings;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPageMargins;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutTarget;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STLayoutMode;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.w3c.dom.Text;
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a SpreadsheetML Chart
|
* Represents a SpreadsheetML Chart
|
||||||
|
* @author Nick Burch
|
||||||
|
* @author Roman Kashitsyn
|
||||||
*/
|
*/
|
||||||
public final class XSSFChart extends POIXMLDocumentPart {
|
public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartAxisFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent graphic frame.
|
||||||
|
*/
|
||||||
|
private XSSFGraphicFrame frame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Root element of the SpreadsheetML Chart part
|
* Root element of the SpreadsheetML Chart part
|
||||||
*/
|
*/
|
||||||
@ -50,11 +78,14 @@ public final class XSSFChart extends POIXMLDocumentPart {
|
|||||||
*/
|
*/
|
||||||
private CTChart chart;
|
private CTChart chart;
|
||||||
|
|
||||||
|
List<XSSFChartAxis> axis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new SpreadsheetML chart
|
* Create a new SpreadsheetML chart
|
||||||
*/
|
*/
|
||||||
protected XSSFChart() {
|
protected XSSFChart() {
|
||||||
super();
|
super();
|
||||||
|
axis = new ArrayList<XSSFChartAxis>();
|
||||||
createChart();
|
createChart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +112,28 @@ public final class XSSFChart extends POIXMLDocumentPart {
|
|||||||
private void createChart() {
|
private void createChart() {
|
||||||
chartSpace = CTChartSpace.Factory.newInstance();
|
chartSpace = CTChartSpace.Factory.newInstance();
|
||||||
chart = chartSpace.addNewChart();
|
chart = chartSpace.addNewChart();
|
||||||
|
CTPlotArea plotArea = chart.addNewPlotArea();
|
||||||
|
CTLayout layout = plotArea.addNewLayout();
|
||||||
|
CTManualLayout manualLayout = layout.addNewManualLayout();
|
||||||
|
manualLayout.addNewLayoutTarget().setVal(STLayoutTarget.INNER);
|
||||||
|
manualLayout.addNewXMode().setVal(STLayoutMode.EDGE);
|
||||||
|
manualLayout.addNewYMode().setVal(STLayoutMode.EDGE);
|
||||||
|
manualLayout.addNewX().setVal(0);
|
||||||
|
manualLayout.addNewY().setVal(0);
|
||||||
|
manualLayout.addNewW().setVal(0.65);
|
||||||
|
manualLayout.addNewH().setVal(0.8);
|
||||||
|
chart.addNewPlotVisOnly().setVal(true);
|
||||||
|
CTPrintSettings printSettings = chartSpace.addNewPrintSettings();
|
||||||
|
printSettings.addNewHeaderFooter();
|
||||||
|
|
||||||
|
CTPageMargins pageMargins = printSettings.addNewPageMargins();
|
||||||
|
pageMargins.setB(0.75);
|
||||||
|
pageMargins.setL(0.70);
|
||||||
|
pageMargins.setR(0.70);
|
||||||
|
pageMargins.setT(0.75);
|
||||||
|
pageMargins.setHeader(0.30);
|
||||||
|
pageMargins.setFooter(0.30);
|
||||||
|
printSettings.addNewPageSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,8 +160,17 @@ public final class XSSFChart extends POIXMLDocumentPart {
|
|||||||
protected void commit() throws IOException {
|
protected void commit() throws IOException {
|
||||||
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Saved chart space must have the following namespaces set:
|
||||||
|
<c:chartSpace
|
||||||
|
xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart"
|
||||||
|
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
|
||||||
|
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
||||||
|
*/
|
||||||
|
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put(XSSFDrawing.NAMESPACE_A, "a");
|
map.put(XSSFDrawing.NAMESPACE_A, "a");
|
||||||
|
map.put(XSSFDrawing.NAMESPACE_C, "c");
|
||||||
map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
|
map.put(STRelationshipId.type.getName().getNamespaceURI(), "r");
|
||||||
xmlOptions.setSaveSuggestedPrefixes(map);
|
xmlOptions.setSaveSuggestedPrefixes(map);
|
||||||
|
|
||||||
@ -118,6 +180,97 @@ public final class XSSFChart extends POIXMLDocumentPart {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the parent graphic frame.
|
||||||
|
* @return the graphic frame this chart belongs to
|
||||||
|
*/
|
||||||
|
public XSSFGraphicFrame getGraphicFrame() {
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the parent graphic frame.
|
||||||
|
*/
|
||||||
|
protected void setGraphicFrame(XSSFGraphicFrame frame) {
|
||||||
|
this.frame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFChartDataFactory getChartDataFactory() {
|
||||||
|
return XSSFChartDataFactory.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFChart getChartAxisFactory() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void plot(ChartData data, ChartAxis... axis) {
|
||||||
|
data.fillChart(this, axis);
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFValueAxis createValueAxis(AxisPosition pos) {
|
||||||
|
long id = axis.size() + 1;
|
||||||
|
XSSFValueAxis valueAxis = new XSSFValueAxis(this, id, pos);
|
||||||
|
if (axis.size() == 1) {
|
||||||
|
ChartAxis ax = axis.get(0);
|
||||||
|
ax.crossAxis(valueAxis);
|
||||||
|
valueAxis.crossAxis(ax);
|
||||||
|
}
|
||||||
|
axis.add(valueAxis);
|
||||||
|
return valueAxis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<? extends XSSFChartAxis> getAxis() {
|
||||||
|
return axis;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the width ratio of the chart.
|
||||||
|
* Chart width is ratio multiplied by parent frame width.
|
||||||
|
* @param ratio a number between 0 and 1.
|
||||||
|
*/
|
||||||
|
public void setWidthRatio(double ratio) {
|
||||||
|
chart.getPlotArea().getLayout().getManualLayout().getW().setVal(ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return relative chart width
|
||||||
|
*/
|
||||||
|
public double getWidthRatio() {
|
||||||
|
return chart.getPlotArea().getLayout().getManualLayout().getW().getVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the height ratio of the chart.
|
||||||
|
* Chart height is ratio multiplied by parent frame height.
|
||||||
|
* @param ratio a number between 0 and 1.
|
||||||
|
*/
|
||||||
|
public void setHeightRatio(double ratio) {
|
||||||
|
chart.getPlotArea().getLayout().getManualLayout().getH().setVal(ratio);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return relative chart height
|
||||||
|
*/
|
||||||
|
public double getHeightRatio() {
|
||||||
|
return chart.getPlotArea().getLayout().getManualLayout().getH().getVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if only visible cells will be present on the chart,
|
||||||
|
* false otherwise
|
||||||
|
*/
|
||||||
|
public boolean isPlotOnlyVisibleCells() {
|
||||||
|
return chart.getPlotVisOnly().getVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param plotVisOnly a flag specifying if only visible cells should be
|
||||||
|
* present on the chart
|
||||||
|
*/
|
||||||
|
public void setPlotOnlyVisibleCells(boolean plotVisOnly) {
|
||||||
|
chart.getPlotVisOnly().setVal(plotVisOnly);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the title, or null if none is set
|
* Returns the title, or null if none is set
|
||||||
*/
|
*/
|
||||||
@ -144,4 +297,14 @@ public final class XSSFChart extends POIXMLDocumentPart {
|
|||||||
return new XSSFRichTextString(text.toString());
|
return new XSSFRichTextString(text.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XSSFChartLegend getOrCreateLegend() {
|
||||||
|
return new XSSFChartLegend(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLegend() {
|
||||||
|
if (chart.isSetLegend()) {
|
||||||
|
chart.unsetLegend();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture;
|
|||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.STEditAs;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,8 +58,10 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
*/
|
*/
|
||||||
private CTDrawing drawing;
|
private CTDrawing drawing;
|
||||||
private boolean isNew;
|
private boolean isNew;
|
||||||
|
private long numOfGraphicFrames = 0L;
|
||||||
|
|
||||||
protected static final String NAMESPACE_A = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
protected static final String NAMESPACE_A = "http://schemas.openxmlformats.org/drawingml/2006/main";
|
||||||
|
protected static final String NAMESPACE_C = "http://schemas.openxmlformats.org/drawingml/2006/chart";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new SpreadsheetML drawing
|
* Create a new SpreadsheetML drawing
|
||||||
@ -125,6 +128,11 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2,
|
||||||
|
int col1, int row1, int col2, int row2) {
|
||||||
|
return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a textbox under the drawing.
|
* Constructs a textbox under the drawing.
|
||||||
*
|
*
|
||||||
@ -169,6 +177,31 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
return createPicture((XSSFClientAnchor)anchor, pictureIndex);
|
return createPicture((XSSFClientAnchor)anchor, pictureIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a chart.
|
||||||
|
* @param anchor the client anchor describes how this chart is attached to
|
||||||
|
* the sheet.
|
||||||
|
* @return the newly created chart
|
||||||
|
* @see org.apache.poi.xssf.usermodel.XSSFDrawing#createChart(ClientAnchor)
|
||||||
|
*/
|
||||||
|
public XSSFChart createChart(XSSFClientAnchor anchor) {
|
||||||
|
int chartNumber = getPackagePart().getPackage().
|
||||||
|
getPartsByContentType(XSSFRelation.CHART.getContentType()).size() + 1;
|
||||||
|
|
||||||
|
XSSFChart chart = (XSSFChart) createRelationship(
|
||||||
|
XSSFRelation.CHART, XSSFFactory.getInstance(), chartNumber);
|
||||||
|
String chartRelId = chart.getPackageRelationship().getId();
|
||||||
|
|
||||||
|
XSSFGraphicFrame frame = createGraphicFrame(anchor);
|
||||||
|
frame.setChart(chart, chartRelId);
|
||||||
|
|
||||||
|
return chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFChart createChart(ClientAnchor anchor) {
|
||||||
|
return createChart((XSSFClientAnchor)anchor);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the indexed picture to this drawing relations
|
* Add the indexed picture to this drawing relations
|
||||||
*
|
*
|
||||||
@ -241,8 +274,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a cell comment.
|
* Creates a comment.
|
||||||
*
|
|
||||||
* @param anchor the client anchor describes how this comment is attached
|
* @param anchor the client anchor describes how this comment is attached
|
||||||
* to the sheet.
|
* to the sheet.
|
||||||
* @return the newly created comment.
|
* @return the newly created comment.
|
||||||
@ -267,6 +299,26 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing {
|
|||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new graphic frame.
|
||||||
|
*
|
||||||
|
* @param anchor the client anchor describes how this frame is attached
|
||||||
|
* to the sheet
|
||||||
|
* @return the newly created graphic frame
|
||||||
|
*/
|
||||||
|
private XSSFGraphicFrame createGraphicFrame(XSSFClientAnchor anchor) {
|
||||||
|
CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
|
||||||
|
CTGraphicalObjectFrame ctGraphicFrame = ctAnchor.addNewGraphicFrame();
|
||||||
|
ctGraphicFrame.set(XSSFGraphicFrame.prototype());
|
||||||
|
|
||||||
|
long frameId = numOfGraphicFrames++;
|
||||||
|
XSSFGraphicFrame graphicFrame = new XSSFGraphicFrame(this, ctGraphicFrame);
|
||||||
|
graphicFrame.setAnchor(anchor);
|
||||||
|
graphicFrame.setId(frameId);
|
||||||
|
graphicFrame.setName("Diagramm" + frameId);
|
||||||
|
return graphicFrame;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all charts in this drawing.
|
* Returns all charts in this drawing.
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
* ====================================================================
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
|
import javax.xml.namespace.QName;
|
||||||
|
|
||||||
|
import org.apache.poi.openxml4j.opc.PackageRelationship;
|
||||||
|
import org.apache.poi.util.Internal;
|
||||||
|
import org.apache.xmlbeans.XmlObject;
|
||||||
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrame;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGraphicalObjectFrameNonVisual;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
|
||||||
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents DrawingML GraphicalObjectFrame.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public final class XSSFGraphicFrame {
|
||||||
|
|
||||||
|
private static CTGraphicalObjectFrame prototype = null;
|
||||||
|
|
||||||
|
private CTGraphicalObjectFrame graphicFrame;
|
||||||
|
private XSSFDrawing drawing;
|
||||||
|
private XSSFClientAnchor anchor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new XSSFGraphicFrame object.
|
||||||
|
*
|
||||||
|
* @param drawing the XSSFDrawing that owns this frame
|
||||||
|
* @param ctGraphicFrame the XML bean that stores this frame content
|
||||||
|
*/
|
||||||
|
protected XSSFGraphicFrame(XSSFDrawing drawing, CTGraphicalObjectFrame ctGraphicFrame) {
|
||||||
|
this.drawing = drawing;
|
||||||
|
this.graphicFrame = ctGraphicFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Internal
|
||||||
|
public CTGraphicalObjectFrame getCTGraphicalObjectFrame() {
|
||||||
|
return graphicFrame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize default structure of a new graphic frame
|
||||||
|
*/
|
||||||
|
protected static CTGraphicalObjectFrame prototype() {
|
||||||
|
if (prototype == null) {
|
||||||
|
CTGraphicalObjectFrame graphicFrame = CTGraphicalObjectFrame.Factory.newInstance();
|
||||||
|
|
||||||
|
CTGraphicalObjectFrameNonVisual nvGraphic = graphicFrame.addNewNvGraphicFramePr();
|
||||||
|
CTNonVisualDrawingProps props = nvGraphic.addNewCNvPr();
|
||||||
|
props.setId(0);
|
||||||
|
props.setName("Diagramm 1");
|
||||||
|
nvGraphic.addNewCNvGraphicFramePr();
|
||||||
|
|
||||||
|
CTTransform2D transform = graphicFrame.addNewXfrm();
|
||||||
|
CTPositiveSize2D extPoint = transform.addNewExt();
|
||||||
|
CTPoint2D offPoint = transform.addNewOff();
|
||||||
|
|
||||||
|
extPoint.setCx(0);
|
||||||
|
extPoint.setCy(0);
|
||||||
|
offPoint.setX(0);
|
||||||
|
offPoint.setY(0);
|
||||||
|
|
||||||
|
CTGraphicalObject graphic = graphicFrame.addNewGraphic();
|
||||||
|
|
||||||
|
prototype = graphicFrame;
|
||||||
|
}
|
||||||
|
return prototype;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the frame macro.
|
||||||
|
*/
|
||||||
|
public void setMacro(String macro) {
|
||||||
|
graphicFrame.setMacro(macro);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the frame name.
|
||||||
|
*/
|
||||||
|
public void setName(String name) {
|
||||||
|
getNonVisualProperties().setName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the frame name.
|
||||||
|
* @return name of the frame
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return getNonVisualProperties().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CTNonVisualDrawingProps getNonVisualProperties() {
|
||||||
|
CTGraphicalObjectFrameNonVisual nvGraphic = graphicFrame.getNvGraphicFramePr();
|
||||||
|
return nvGraphic.getCNvPr();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attaches frame to an anchor.
|
||||||
|
*/
|
||||||
|
protected void setAnchor(XSSFClientAnchor anchor) {
|
||||||
|
this.anchor = anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the frame anchor.
|
||||||
|
* @return the anchor this frame is attached to
|
||||||
|
*/
|
||||||
|
public XSSFClientAnchor getAnchor() {
|
||||||
|
return anchor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assign a DrawingML chart to the graphic frame.
|
||||||
|
*/
|
||||||
|
protected void setChart(XSSFChart chart, String relId) {
|
||||||
|
CTGraphicalObjectData data = graphicFrame.getGraphic().addNewGraphicData();
|
||||||
|
appendChartElement(data, relId);
|
||||||
|
chart.setGraphicFrame(this);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the frame id.
|
||||||
|
*/
|
||||||
|
public long getId() {
|
||||||
|
return graphicFrame.getNvGraphicFramePr().getCNvPr().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the frame id.
|
||||||
|
*/
|
||||||
|
protected void setId(long id) {
|
||||||
|
graphicFrame.getNvGraphicFramePr().getCNvPr().setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The low level code to insert {@code <c:chart>} tag into
|
||||||
|
* {@code<a:graphicData>}.
|
||||||
|
*
|
||||||
|
* Here is the schema (ECMA-376):
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* <complexType name="CT_GraphicalObjectData">
|
||||||
|
* <sequence>
|
||||||
|
* <any minOccurs="0" maxOccurs="unbounded" processContents="strict"/>
|
||||||
|
* </sequence>
|
||||||
|
* <attribute name="uri" type="xsd:token"/>
|
||||||
|
* </complexType>
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
private void appendChartElement(CTGraphicalObjectData data, String id) {
|
||||||
|
String r_namespaceUri = STRelationshipId.type.getName().getNamespaceURI();
|
||||||
|
String c_namespaceUri = XSSFDrawing.NAMESPACE_C;
|
||||||
|
XmlCursor cursor = data.newCursor();
|
||||||
|
cursor.toNextToken();
|
||||||
|
cursor.beginElement(new QName(c_namespaceUri, "chart", "c"));
|
||||||
|
cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id);
|
||||||
|
cursor.dispose();
|
||||||
|
data.setUri(c_namespaceUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,223 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisPosition;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTOrientation;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLogBase;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all axis types.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public abstract class XSSFChartAxis implements ChartAxis {
|
||||||
|
|
||||||
|
protected XSSFChart chart;
|
||||||
|
|
||||||
|
private static final double MIN_LOG_BASE = 2.0;
|
||||||
|
private static final double MAX_LOG_BASE = 1000.0;
|
||||||
|
|
||||||
|
protected XSSFChartAxis(XSSFChart chart) {
|
||||||
|
this.chart = chart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisPosition getPosition() {
|
||||||
|
return toAxisPosition(getCTAxPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(AxisPosition position) {
|
||||||
|
getCTAxPos().setVal(fromAxisPosition(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumberFormat(String format) {
|
||||||
|
getCTNumFmt().setFormatCode(format);
|
||||||
|
getCTNumFmt().setSourceLinked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNumberFormat() {
|
||||||
|
return getCTNumFmt().getFormatCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSetLogBase() {
|
||||||
|
return getCTScaling().isSetLogBase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLogBase(double logBase) {
|
||||||
|
if (logBase < MIN_LOG_BASE ||
|
||||||
|
MAX_LOG_BASE < logBase) {
|
||||||
|
throw new IllegalArgumentException("Axis log base must be between 2 and 1000 (inclusive), got: " + logBase);
|
||||||
|
}
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
if (scaling.isSetLogBase()) {
|
||||||
|
scaling.getLogBase().setVal(logBase);
|
||||||
|
} else {
|
||||||
|
scaling.addNewLogBase().setVal(logBase);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLogBase() {
|
||||||
|
CTLogBase logBase = getCTScaling().getLogBase();
|
||||||
|
if (logBase != null) {
|
||||||
|
return logBase.getVal();
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSetMinimum() {
|
||||||
|
return getCTScaling().isSetMin();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMinimum(double min) {
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
if (scaling.isSetMin()) {
|
||||||
|
scaling.getMin().setVal(min);
|
||||||
|
} else {
|
||||||
|
scaling.addNewMin().setVal(min);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMinimum() {
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
if (scaling.isSetMin()) {
|
||||||
|
return scaling.getMin().getVal();
|
||||||
|
} else {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSetMaximum() {
|
||||||
|
return getCTScaling().isSetMax();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaximum(double max) {
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
if (scaling.isSetMax()) {
|
||||||
|
scaling.getMax().setVal(max);
|
||||||
|
} else {
|
||||||
|
scaling.addNewMax().setVal(max);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMaximum() {
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
if (scaling.isSetMax()) {
|
||||||
|
return scaling.getMax().getVal();
|
||||||
|
} else {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisOrientation getOrientation() {
|
||||||
|
return toAxisOrientation(getCTScaling().getOrientation());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(AxisOrientation orientation) {
|
||||||
|
CTScaling scaling = getCTScaling();
|
||||||
|
STOrientation.Enum stOrientation = fromAxisOrientation(orientation);
|
||||||
|
if (scaling.isSetOrientation()) {
|
||||||
|
scaling.getOrientation().setVal(stOrientation);
|
||||||
|
} else {
|
||||||
|
getCTScaling().addNewOrientation().setVal(stOrientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisCrosses getCrosses() {
|
||||||
|
return toAxisCrosses(getCTCrosses());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrosses(AxisCrosses crosses) {
|
||||||
|
getCTCrosses().setVal(fromAxisCrosses(crosses));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract CTAxPos getCTAxPos();
|
||||||
|
protected abstract CTNumFmt getCTNumFmt();
|
||||||
|
protected abstract CTScaling getCTScaling();
|
||||||
|
protected abstract CTCrosses getCTCrosses();
|
||||||
|
|
||||||
|
private static STOrientation.Enum fromAxisOrientation(AxisOrientation orientation) {
|
||||||
|
switch (orientation) {
|
||||||
|
case MIN_MAX: return STOrientation.MIN_MAX;
|
||||||
|
case MAX_MIN: return STOrientation.MAX_MIN;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AxisOrientation toAxisOrientation(CTOrientation ctOrientation) {
|
||||||
|
switch (ctOrientation.getVal().intValue()) {
|
||||||
|
case STOrientation.INT_MIN_MAX: return AxisOrientation.MIN_MAX;
|
||||||
|
case STOrientation.INT_MAX_MIN: return AxisOrientation.MAX_MIN;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static STCrosses.Enum fromAxisCrosses(AxisCrosses crosses) {
|
||||||
|
switch (crosses) {
|
||||||
|
case AUTO_ZERO: return STCrosses.AUTO_ZERO;
|
||||||
|
case MIN: return STCrosses.MIN;
|
||||||
|
case MAX: return STCrosses.MAX;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AxisCrosses toAxisCrosses(CTCrosses ctCrosses) {
|
||||||
|
switch (ctCrosses.getVal().intValue()) {
|
||||||
|
case STCrosses.INT_AUTO_ZERO: return AxisCrosses.AUTO_ZERO;
|
||||||
|
case STCrosses.INT_MAX: return AxisCrosses.MAX;
|
||||||
|
case STCrosses.INT_MIN: return AxisCrosses.MIN;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static STAxPos.Enum fromAxisPosition(AxisPosition position) {
|
||||||
|
switch (position) {
|
||||||
|
case BOTTOM: return STAxPos.B;
|
||||||
|
case LEFT: return STAxPos.L;
|
||||||
|
case RIGHT: return STAxPos.R;
|
||||||
|
case TOP: return STAxPos.T;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AxisPosition toAxisPosition(CTAxPos ctAxPos) {
|
||||||
|
switch (ctAxPos.getVal().intValue()) {
|
||||||
|
case STAxPos.INT_B: return AxisPosition.BOTTOM;
|
||||||
|
case STAxPos.INT_L: return AxisPosition.LEFT;
|
||||||
|
case STAxPos.INT_R: return AxisPosition.RIGHT;
|
||||||
|
case STAxPos.INT_T: return AxisPosition.TOP;
|
||||||
|
default: return AxisPosition.BOTTOM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public class XSSFChartDataFactory implements ChartDataFactory {
|
||||||
|
|
||||||
|
private static XSSFChartDataFactory instance;
|
||||||
|
|
||||||
|
private XSSFChartDataFactory() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return new scatter chart data instance
|
||||||
|
*/
|
||||||
|
public XSSFScatterChartData createScatterChartData() {
|
||||||
|
return new XSSFScatterChartData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return factory instance
|
||||||
|
*/
|
||||||
|
public static XSSFChartDataFactory getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new XSSFChartDataFactory();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.util.Internal;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartLegend;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.LegendPosition;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegend;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTLegendPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STLegendPos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a SpreadsheetML chart legend
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public final class XSSFChartLegend implements ChartLegend {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Underlaying CTLagend bean
|
||||||
|
*/
|
||||||
|
private CTLegend legend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new SpreadsheetML chart legend
|
||||||
|
*/
|
||||||
|
public XSSFChartLegend(XSSFChart chart) {
|
||||||
|
CTChart ctChart = chart.getCTChart();
|
||||||
|
this.legend = (ctChart.isSetLegend()) ?
|
||||||
|
ctChart.getLegend() :
|
||||||
|
ctChart.addNewLegend();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the underlying CTLegend bean.
|
||||||
|
*
|
||||||
|
* @return the underlying CTLegend bean
|
||||||
|
*/
|
||||||
|
@Internal
|
||||||
|
public CTLegend getCTLegend(){
|
||||||
|
return legend;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(LegendPosition position) {
|
||||||
|
if (!legend.isSetLegendPos()) {
|
||||||
|
legend.addNewLegendPos();
|
||||||
|
}
|
||||||
|
legend.getLegendPos().setVal(fromLegendPosition(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* According to ECMA-376 default position is RIGHT.
|
||||||
|
*/
|
||||||
|
public LegendPosition getPosition() {
|
||||||
|
if (legend.isSetLegendPos()) {
|
||||||
|
return toLegendPosition(legend.getLegendPos());
|
||||||
|
} else {
|
||||||
|
return LegendPosition.RIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private STLegendPos.Enum fromLegendPosition(LegendPosition position) {
|
||||||
|
switch (position) {
|
||||||
|
case BOTTOM: return STLegendPos.B;
|
||||||
|
case LEFT: return STLegendPos.L;
|
||||||
|
case RIGHT: return STLegendPos.R;
|
||||||
|
case TOP: return STLegendPos.T;
|
||||||
|
case TOP_RIGHT: return STLegendPos.TR;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LegendPosition toLegendPosition(CTLegendPos ctLegendPos) {
|
||||||
|
switch (ctLegendPos.getVal().intValue()) {
|
||||||
|
case STLegendPos.INT_B: return LegendPosition.BOTTOM;
|
||||||
|
case STLegendPos.INT_L: return LegendPosition.LEFT;
|
||||||
|
case STLegendPos.INT_R: return LegendPosition.RIGHT;
|
||||||
|
case STLegendPos.INT_T: return LegendPosition.TOP;
|
||||||
|
case STLegendPos.INT_TR: return LegendPosition.TOP_RIGHT;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,147 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Chart;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ScatterChartData;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ScatterChartSerie;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartDataFactory;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
|
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterStyle;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScatterSer;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumRef;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STScatterStyle;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrosses;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STOrientation;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
|
||||||
|
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents DrawingML scatter chart.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public class XSSFScatterChartData implements ScatterChartData {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of all data series.
|
||||||
|
*/
|
||||||
|
private List<Serie> series;
|
||||||
|
|
||||||
|
public XSSFScatterChartData() {
|
||||||
|
series = new ArrayList<Serie>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Serie implements ScatterChartSerie {
|
||||||
|
private int id;
|
||||||
|
private int order;
|
||||||
|
private boolean useCache;
|
||||||
|
private Sheet xSheet;
|
||||||
|
private Sheet ySheet;
|
||||||
|
private CellRangeAddress xAddress;
|
||||||
|
private CellRangeAddress yAddress;
|
||||||
|
|
||||||
|
public Serie(int id, int order) {
|
||||||
|
super();
|
||||||
|
this.id = id;
|
||||||
|
this.order = order;
|
||||||
|
this.useCache = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setXValues(Sheet sheet, CellRangeAddress address) {
|
||||||
|
this.xSheet = sheet;
|
||||||
|
this.xAddress = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYValues(Sheet sheet, CellRangeAddress address) {
|
||||||
|
this.ySheet = sheet;
|
||||||
|
this.yAddress = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param useCache if true, cached results will be added on plot
|
||||||
|
*/
|
||||||
|
public void setUseCache(boolean useCache) {
|
||||||
|
this.useCache = useCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addToChart(CTScatterChart ctScatterChart) {
|
||||||
|
CTScatterSer scatterSer = ctScatterChart.addNewSer();
|
||||||
|
scatterSer.addNewIdx().setVal(this.id);
|
||||||
|
scatterSer.addNewOrder().setVal(this.order);
|
||||||
|
|
||||||
|
CTAxDataSource xVal = scatterSer.addNewXVal();
|
||||||
|
CTNumRef numRef = xVal.addNewNumRef();
|
||||||
|
numRef.setF(xAddress.formatAsString(xSheet.getSheetName(), true));
|
||||||
|
|
||||||
|
CTNumDataSource yVal = scatterSer.addNewYVal();
|
||||||
|
numRef = yVal.addNewNumRef();
|
||||||
|
numRef.setF(yAddress.formatAsString(ySheet.getSheetName(), true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public XSSFScatterChartData.Serie addSerie() {
|
||||||
|
int numOfSeries = series.size();
|
||||||
|
Serie newSerie = new Serie(numOfSeries, numOfSeries);
|
||||||
|
series.add(newSerie);
|
||||||
|
return newSerie;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fillChart(Chart chart, ChartAxis... axis) {
|
||||||
|
if (!(chart instanceof XSSFChart)) {
|
||||||
|
throw new IllegalArgumentException("Chart must be instance of XSSFChart");
|
||||||
|
}
|
||||||
|
|
||||||
|
XSSFChart xssfChart = (XSSFChart) chart;
|
||||||
|
CTPlotArea plotArea = xssfChart.getCTChart().getPlotArea();
|
||||||
|
CTScatterChart scatterChart = plotArea.addNewScatterChart();
|
||||||
|
addStyle(scatterChart);
|
||||||
|
|
||||||
|
for (Serie s : series) {
|
||||||
|
s.addToChart(scatterChart);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ChartAxis ax : axis) {
|
||||||
|
scatterChart.addNewAxId().setVal(ax.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<? extends Serie> getSeries() {
|
||||||
|
return series;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addStyle(CTScatterChart ctScatterChart) {
|
||||||
|
CTScatterStyle scatterStyle = ctScatterChart.addNewScatterStyle();
|
||||||
|
scatterStyle.setVal(STScatterStyle.LINE_MARKER);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,123 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartAxis;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ValueAxis;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisPosition;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisOrientation;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisCrossBetween;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.AxisCrosses;
|
||||||
|
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFChart;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTAxPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTNumFmt;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTCrosses;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.CTScaling;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STAxPos;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STCrossBetween;
|
||||||
|
import org.openxmlformats.schemas.drawingml.x2006.chart.STTickLblPos;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value axis type.
|
||||||
|
*
|
||||||
|
* @author Roman Kashitsyn
|
||||||
|
*/
|
||||||
|
public class XSSFValueAxis extends XSSFChartAxis implements ValueAxis {
|
||||||
|
|
||||||
|
private CTValAx ctValAx;
|
||||||
|
|
||||||
|
public XSSFValueAxis(XSSFChart chart, long id, AxisPosition pos) {
|
||||||
|
super(chart);
|
||||||
|
createAxis(id, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return ctValAx.getAxId().getVal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossBetween(AxisCrossBetween crossBetween) {
|
||||||
|
ctValAx.getCrossBetween().setVal(fromCrossBetween(crossBetween));
|
||||||
|
}
|
||||||
|
|
||||||
|
public AxisCrossBetween getCrossBetween() {
|
||||||
|
return toCrossBetween(ctValAx.getCrossBetween().getVal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CTAxPos getCTAxPos() {
|
||||||
|
return ctValAx.getAxPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CTNumFmt getCTNumFmt() {
|
||||||
|
if (ctValAx.isSetNumFmt()) {
|
||||||
|
return ctValAx.getNumFmt();
|
||||||
|
}
|
||||||
|
return ctValAx.addNewNumFmt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CTScaling getCTScaling() {
|
||||||
|
return ctValAx.getScaling();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CTCrosses getCTCrosses() {
|
||||||
|
return ctValAx.getCrosses();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void crossAxis(ChartAxis axis) {
|
||||||
|
ctValAx.getCrossAx().setVal(axis.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAxis(long id, AxisPosition pos) {
|
||||||
|
ctValAx = chart.getCTChart().getPlotArea().addNewValAx();
|
||||||
|
ctValAx.addNewAxId().setVal(id);
|
||||||
|
ctValAx.addNewAxPos();
|
||||||
|
ctValAx.addNewScaling();
|
||||||
|
ctValAx.addNewCrossBetween();
|
||||||
|
ctValAx.addNewCrosses();
|
||||||
|
ctValAx.addNewCrossAx();
|
||||||
|
ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
|
||||||
|
|
||||||
|
setPosition(pos);
|
||||||
|
setOrientation(AxisOrientation.MIN_MAX);
|
||||||
|
setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
|
||||||
|
setCrosses(AxisCrosses.AUTO_ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static STCrossBetween.Enum fromCrossBetween(AxisCrossBetween crossBetween) {
|
||||||
|
switch (crossBetween) {
|
||||||
|
case BETWEEN: return STCrossBetween.BETWEEN;
|
||||||
|
case MIDPOINT_CATEGORY: return STCrossBetween.MID_CAT;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AxisCrossBetween toCrossBetween(STCrossBetween.Enum ctCrossBetween) {
|
||||||
|
switch (ctCrossBetween.intValue()) {
|
||||||
|
case STCrossBetween.INT_BETWEEN: return AxisCrossBetween.BETWEEN;
|
||||||
|
case STCrossBetween.INT_MID_CAT: return AxisCrossBetween.MIDPOINT_CATEGORY;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -55,4 +55,20 @@ public final class TestXSSFChart extends TestCase {
|
|||||||
chart = s3.createDrawingPatriarch().getCharts().get(0);
|
chart = s3.createDrawingPatriarch().getCharts().get(0);
|
||||||
assertEquals("Sheet 3 Chart with Title", chart.getTitle().getString());
|
assertEquals("Sheet 3 Chart with Title", chart.getTitle().getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAddChartsToNewWorkbook() throws Exception {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet s1 = wb.createSheet();
|
||||||
|
XSSFDrawing d1 = s1.createDrawingPatriarch();
|
||||||
|
XSSFClientAnchor a1 = new XSSFClientAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
XSSFChart c1 = d1.createChart(a1);
|
||||||
|
|
||||||
|
assertEquals(1, d1.getCharts().size());
|
||||||
|
assertNotNull(c1.getGraphicFrame());
|
||||||
|
assertNotNull(c1.getOrCreateLegend());
|
||||||
|
|
||||||
|
XSSFClientAnchor a2 = new XSSFClientAnchor(0, 0, 0, 0, 1, 11, 10, 60);
|
||||||
|
XSSFChart c2 = d1.createChart(a2);
|
||||||
|
assertEquals(2, d1.getCharts().size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.*;
|
||||||
|
|
||||||
|
public final class TestXSSFChartAxis extends TestCase {
|
||||||
|
|
||||||
|
private static final double EPSILON = 1E-7;
|
||||||
|
private XSSFChartAxis axis;
|
||||||
|
|
||||||
|
public TestXSSFChartAxis() {
|
||||||
|
super();
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
XSSFChart chart = drawing.createChart(anchor);
|
||||||
|
axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLogBaseIllegalArgument() throws Exception {
|
||||||
|
IllegalArgumentException iae = null;
|
||||||
|
try {
|
||||||
|
axis.setLogBase(0.0);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
iae = e;
|
||||||
|
}
|
||||||
|
assertNotNull(iae);
|
||||||
|
|
||||||
|
iae = null;
|
||||||
|
try {
|
||||||
|
axis.setLogBase(30000.0);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
iae = e;
|
||||||
|
}
|
||||||
|
assertNotNull(iae);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLogBaseLegalArgument() throws Exception {
|
||||||
|
axis.setLogBase(Math.E);
|
||||||
|
assertTrue(Math.abs(axis.getLogBase() - Math.E) < EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testNumberFormat() throws Exception {
|
||||||
|
final String numberFormat = "General";
|
||||||
|
axis.setNumberFormat(numberFormat);
|
||||||
|
assertEquals(numberFormat, axis.getNumberFormat());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMaxAndMinAccessMethods() {
|
||||||
|
final double newValue = 10.0;
|
||||||
|
|
||||||
|
axis.setMinimum(newValue);
|
||||||
|
assertTrue(Math.abs(axis.getMinimum() - newValue) < EPSILON);
|
||||||
|
|
||||||
|
axis.setMaximum(newValue);
|
||||||
|
assertTrue(Math.abs(axis.getMaximum() - newValue) < EPSILON);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.ChartLegend;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.LegendPosition;
|
||||||
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
|
||||||
|
public final class TestXSSFChartLegend extends TestCase {
|
||||||
|
|
||||||
|
public void testLegendPositionAccessMethods() throws Exception {
|
||||||
|
Workbook wb = new XSSFWorkbook();
|
||||||
|
Sheet sheet = wb.createSheet();
|
||||||
|
Drawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
Chart chart = drawing.createChart(anchor);
|
||||||
|
ChartLegend legend = chart.getOrCreateLegend();
|
||||||
|
|
||||||
|
legend.setPosition(LegendPosition.TOP_RIGHT);
|
||||||
|
assertEquals(LegendPosition.TOP_RIGHT, legend.getPosition());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.ss.usermodel.charts.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.XSSFChartDataFactory;
|
||||||
|
|
||||||
|
public final class TestXSSFScatterChartData extends TestCase {
|
||||||
|
|
||||||
|
public void testOneSeriePlot() throws Exception {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
XSSFChart chart = drawing.createChart(anchor);
|
||||||
|
|
||||||
|
ChartAxis bottomAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
|
||||||
|
ChartAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
|
||||||
|
|
||||||
|
ScatterChartData scatterChartData =
|
||||||
|
XSSFChartDataFactory.getInstance().createScatterChartData();
|
||||||
|
|
||||||
|
ScatterChartSerie serie = scatterChartData.addSerie();
|
||||||
|
serie.setXValues(sheet, new CellRangeAddress(0,0,1,10));
|
||||||
|
serie.setYValues(sheet, new CellRangeAddress(1,1,1,10));
|
||||||
|
|
||||||
|
assertEquals(scatterChartData.getSeries().size(), 1);
|
||||||
|
|
||||||
|
chart.plot(scatterChartData, bottomAxis, leftAxis);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
/* ====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==================================================================== */
|
||||||
|
|
||||||
|
package org.apache.poi.xssf.usermodel.charts;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.charts.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.charts.*;
|
||||||
|
|
||||||
|
public final class TestXSSFValueAxis extends TestCase {
|
||||||
|
|
||||||
|
public void testAccessMethods() throws Exception {
|
||||||
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
|
XSSFSheet sheet = wb.createSheet();
|
||||||
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 1, 1, 10, 30);
|
||||||
|
XSSFChart chart = drawing.createChart(anchor);
|
||||||
|
XSSFValueAxis axis = chart.getChartAxisFactory().createValueAxis(AxisPosition.BOTTOM);
|
||||||
|
|
||||||
|
axis.setCrossBetween(AxisCrossBetween.MIDPOINT_CATEGORY);
|
||||||
|
assertEquals(axis.getCrossBetween(), AxisCrossBetween.MIDPOINT_CATEGORY);
|
||||||
|
|
||||||
|
axis.setCrosses(AxisCrosses.AUTO_ZERO);
|
||||||
|
assertEquals(axis.getCrosses(), AxisCrosses.AUTO_ZERO);
|
||||||
|
|
||||||
|
assertEquals(chart.getAxis().size(), 1);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user