ASF Bugzilla – Attachment 27021 Details for
Bug 51196
[PATCH] Patch to simplify XSSFChart creation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Cumulative patch for scatter chart creation support draft.
scatterChart.patch (text/plain), 49.92 KB, created by
Roman Kashitsyn
on 2011-05-18 09:27:32 UTC
(
hide
)
Description:
Cumulative patch for scatter chart creation support draft.
Filename:
MIME Type:
Creator:
Roman Kashitsyn
Created:
2011-05-18 09:27:32 UTC
Size:
49.92 KB
patch
obsolete
>diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java >new file mode 100644 >index 0000000..458a268 >--- /dev/null >+++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java >@@ -0,0 +1,93 @@ >+/* ==================================================================== >+ 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.xssf.usermodel.*; >+import org.apache.poi.ss.usermodel.charts.*; >+import org.apache.poi.xssf.usermodel.XSSFWorkbook; >+ >+/** >+ * Illustrates how to create cell and set values of different types. >+ */ >+public class ScatterChart { >+ >+ >+ public static void main(String[]args) throws Exception { >+ XSSFWorkbook wb = new XSSFWorkbook(); >+ CreationHelper creationHelper = wb.getCreationHelper(); >+ XSSFSheet 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)); >+ } >+ } >+ >+ row = sheet.createRow((short)1); >+ for (int i = 0; i < 10; i++) { >+ cell = row.createCell((short)i); >+ cell.setCellValue(i * 2); >+ } >+ >+ row = sheet.createRow((short)2); >+ for (int i = 0; i < 10; i++) { >+ cell = row.createCell((short)i); >+ cell.setCellValue(i * 3); >+ } >+ >+ XSSFClientAnchor anchor = new XSSFClientAnchor(0,0,0,0,0,NUM_OF_COLUMNS + 1,NUM_OF_COLUMNS,NUM_OF_ROWS + 10); >+ >+ XSSFDrawing drawing = sheet.createDrawingPatriarch(); >+ >+ XSSFChart chart = drawing.createChart(anchor); >+ XSSFChartLegend legend = chart.getOrCreateLegend(); >+ legend.setPosition(XSSFChartLegend.Position.RIGHT); >+ >+ ScatterChartData data = chart.getChartDataFactory().getScatterChartData(); >+ >+ 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.setXValues(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(); >+ } >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/Chart.java b/src/java/org/apache/poi/ss/usermodel/Chart.java >new file mode 100644 >index 0000000..9343721 >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/Chart.java >@@ -0,0 +1,55 @@ >+/* ==================================================================== >+ 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.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 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); >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/AxisCrossBetween.java b/src/java/org/apache/poi/ss/usermodel/charts/AxisCrossBetween.java >new file mode 100644 >index 0000000..d470cf6 >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/AxisCrossBetween.java >@@ -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 >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java b/src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java >new file mode 100644 >index 0000000..906198b >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/AxisCrosses.java >@@ -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 >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/AxisOrientation.java b/src/java/org/apache/poi/ss/usermodel/charts/AxisOrientation.java >new file mode 100644 >index 0000000..e8c219b >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/AxisOrientation.java >@@ -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 >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/AxisPosition.java b/src/java/org/apache/poi/ss/usermodel/charts/AxisPosition.java >new file mode 100644 >index 0000000..db189f9 >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/AxisPosition.java >@@ -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 >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java b/src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java >new file mode 100644 >index 0000000..d58731c >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ChartAxis.java >@@ -0,0 +1,107 @@ >+/* ==================================================================== >+ 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 new axis position >+ */ >+ void setPosition(AxisPosition position); >+ >+ /** >+ * @return axis number format >+ */ >+ String getNumberFormat(); >+ >+ /** >+ * @param format axis number format >+ */ >+ void setNumberFormat(String format); >+ >+ /** >+ * @param logBase a number between 2 and 1000 (inclusive) >+ */ >+ void setLogBase(Double logBase); >+ >+ /** >+ * @return axis log base or null if not set >+ */ >+ Double getLogBase(); >+ >+ /** >+ * @return axis minimum or null if not set >+ */ >+ Double getMinimum(); >+ >+ /** >+ * @param min axis minimum >+ */ >+ void setMinimum(Double min); >+ >+ /** >+ * @return axis maximum or null 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); >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java b/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java >new file mode 100644 >index 0000000..9c1e09d >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ChartAxisFactory.java >@@ -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); >+ >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ChartData.java b/src/java/org/apache/poi/ss/usermodel/charts/ChartData.java >new file mode 100644 >index 0000000..f2acc6f >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ChartData.java >@@ -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); >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ChartDataFactory.java b/src/java/org/apache/poi/ss/usermodel/charts/ChartDataFactory.java >new file mode 100644 >index 0000000..b37faea >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ChartDataFactory.java >@@ -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 getScatterChartData(); >+ >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartData.java b/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartData.java >new file mode 100644 >index 0000000..7f828d7 >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartData.java >@@ -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(); >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartSerie.java b/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartSerie.java >new file mode 100644 >index 0000000..274113b >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ScatterChartSerie.java >@@ -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); >+ >+} >diff --git a/src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java b/src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java >new file mode 100644 >index 0000000..5613257 >--- /dev/null >+++ b/src/java/org/apache/poi/ss/usermodel/charts/ValueAxis.java >@@ -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); >+} >diff --git a/src/java/org/apache/poi/ss/util/CellRangeAddress.java b/src/java/org/apache/poi/ss/util/CellRangeAddress.java >index 2c34d5f..4a7ec73 100644 >--- a/src/java/org/apache/poi/ss/util/CellRangeAddress.java >+++ b/src/java/org/apache/poi/ss/util/CellRangeAddress.java >@@ -80,10 +80,24 @@ public class CellRangeAddress extends CellRangeAddressBase { > * like single cell references (e.g. 'A1' instead of 'A1:A1'). > */ > 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(); >- CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn()); >- CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn()); >+ if (sheetName != null) { >+ 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()); >+ > //for a single-cell reference return A1 instead of A1:A1 > if(!cellRefFrom.equals(cellRefTo)){ > sb.append(':'); >diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java >index d184f87..1b949c6 100644 >--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java >@@ -21,6 +21,8 @@ import java.io.IOException; > import java.io.OutputStream; > import java.util.HashMap; > import java.util.Map; >+import java.util.List; >+import java.util.ArrayList; > > import javax.xml.namespace.QName; > >@@ -28,6 +30,14 @@ import org.apache.poi.POIXMLDocumentPart; > import org.apache.poi.openxml4j.opc.PackagePart; > import org.apache.poi.openxml4j.opc.PackageRelationship; > 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.ss.usermodel.charts.ChartData; >+import org.apache.poi.ss.usermodel.charts.AxisPosition; > import org.apache.xmlbeans.XmlException; > import org.apache.xmlbeans.XmlObject; > import org.apache.xmlbeans.XmlOptions; >@@ -51,7 +61,7 @@ import org.w3c.dom.Text; > * @author Nick Burch > * @author Roman Kashitsyn > */ >-public final class XSSFChart extends POIXMLDocumentPart { >+public final class XSSFChart extends POIXMLDocumentPart implements Chart, ChartAxisFactory { > > /** > * Parent graphic frame. >@@ -67,11 +77,14 @@ public final class XSSFChart extends POIXMLDocumentPart { > */ > private CTChart chart; > >+ List<XSSFChartAxis> axis; >+ > /** > * Create a new SpreadsheetML chart > */ > protected XSSFChart() { > super(); >+ axis = new ArrayList<XSSFChartAxis>(); > createChart(); > } > >@@ -143,28 +156,28 @@ public final class XSSFChart extends POIXMLDocumentPart { > } > > @Override >- protected void commit() throws IOException { >- 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.put(XSSFDrawing.NAMESPACE_A, "a"); >- map.put(XSSFDrawing.NAMESPACE_C, "c"); >- map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); >- xmlOptions.setSaveSuggestedPrefixes(map); >- >- PackagePart part = getPackagePart(); >- OutputStream out = part.getOutputStream(); >- chartSpace.save(out, xmlOptions); >- out.close(); >- } >+ protected void commit() throws IOException { >+ 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.put(XSSFDrawing.NAMESPACE_A, "a"); >+ map.put(XSSFDrawing.NAMESPACE_C, "c"); >+ map.put(STRelationshipId.type.getName().getNamespaceURI(), "r"); >+ xmlOptions.setSaveSuggestedPrefixes(map); >+ >+ PackagePart part = getPackagePart(); >+ OutputStream out = part.getOutputStream(); >+ chartSpace.save(out, xmlOptions); >+ out.close(); >+ } > > /** > * Returns the parent graphic frame. >@@ -181,6 +194,39 @@ public final class XSSFChart extends POIXMLDocumentPart { > this.frame = frame; > } > >+ @Override >+ public XSSFChartDataFactory getChartDataFactory() { >+ return XSSFChartDataFactory.getInstance(); >+ } >+ >+ @Override >+ public XSSFChart getChartAxisFactory() { >+ return this; >+ } >+ >+ @Override >+ public void plot(ChartData data, ChartAxis... axis) { >+ data.fillChart(this, axis); >+ } >+ >+ @Override >+ 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; >+ } >+ >+ @Override >+ public List<? extends XSSFChartAxis> getAxis() { >+ return axis; >+ } >+ > /** > * Sets the width ratio of the chart. > * Chart width is ratio multiplied by parent frame width. >diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartAxis.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartAxis.java >new file mode 100644 >index 0000000..34624c3 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartAxis.java >@@ -0,0 +1,225 @@ >+/* ==================================================================== >+ 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; >+ } >+ >+ @Override >+ public AxisPosition getPosition() { >+ return toAxisPosition(getCTAxPos()); >+ } >+ >+ @Override >+ public void setPosition(AxisPosition position) { >+ getCTAxPos().setVal(fromAxisPosition(position)); >+ } >+ >+ @Override >+ public void setNumberFormat(String format) { >+ getCTNumFmt().setFormatCode(format); >+ getCTNumFmt().setSourceLinked(true); >+ } >+ >+ @Override >+ public String getNumberFormat() { >+ return getCTNumFmt().getFormatCode(); >+ } >+ >+ @Override >+ 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.doubleValue()); >+ } else { >+ scaling.addNewLogBase().setVal(logBase.doubleValue()); >+ } >+ } >+ >+ @Override >+ public Double getLogBase() { >+ CTLogBase logBase = getCTScaling().getLogBase(); >+ if (logBase != null) { >+ return Double.valueOf(logBase.getVal()); >+ } >+ return null; >+ } >+ >+ @Override >+ public void setMinimum(Double min) { >+ CTScaling scaling = getCTScaling(); >+ if (scaling.isSetMin()) { >+ scaling.getMin().setVal(min.doubleValue()); >+ } else { >+ scaling.addNewMin().setVal(min.doubleValue()); >+ } >+ } >+ >+ @Override >+ public Double getMinimum() { >+ CTScaling scaling = getCTScaling(); >+ if (scaling.isSetMin()) { >+ return Double.valueOf(scaling.getMin().getVal()); >+ } else { >+ return null; >+ } >+ } >+ >+ @Override >+ public void setMaximum(Double max) { >+ CTScaling scaling = getCTScaling(); >+ if (scaling.isSetMax()) { >+ scaling.getMax().setVal(max.doubleValue()); >+ } else { >+ scaling.addNewMax().setVal(max.doubleValue()); >+ } >+ } >+ >+ @Override >+ public Double getMaximum() { >+ CTScaling scaling = getCTScaling(); >+ if (scaling.isSetMax()) { >+ return Double.valueOf(scaling.getMax().getVal()); >+ } else { >+ return null; >+ } >+ } >+ >+ @Override >+ public AxisOrientation getOrientation() { >+ return toAxisOrientation(getCTScaling().getOrientation()); >+ } >+ >+ @Override >+ 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); >+ } >+ } >+ >+ @Override >+ public AxisCrosses getCrosses() { >+ return toAxisCrosses(getCTCrosses()); >+ } >+ >+ @Override >+ 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; >+ } >+ } >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartDataFactory.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartDataFactory.java >new file mode 100644 >index 0000000..15b0e82 >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFChartDataFactory.java >@@ -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 getScatterChartData() { >+ return new XSSFScatterChartData(); >+ } >+ >+ /** >+ * @return factory instance >+ */ >+ public static XSSFChartDataFactory getInstance() { >+ if (instance == null) { >+ instance = new XSSFChartDataFactory(); >+ } >+ return instance; >+ } >+ >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFScatterChartData.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFScatterChartData.java >new file mode 100644 >index 0000000..cfbc57d >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFScatterChartData.java >@@ -0,0 +1,152 @@ >+/* ==================================================================== >+ 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; >+ } >+ >+ @Override >+ public void setXValues(Sheet sheet, CellRangeAddress address) { >+ this.xSheet = sheet; >+ this.xAddress = address; >+ } >+ >+ @Override >+ 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)); >+ } >+ } >+ >+ @Override >+ public XSSFScatterChartData.Serie addSerie() { >+ int numOfSeries = series.size(); >+ Serie newSerie = new Serie(numOfSeries, numOfSeries); >+ series.add(newSerie); >+ return newSerie; >+ } >+ >+ @Override >+ 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()); >+ } >+ } >+ >+ @Override >+ public List<? extends Serie> getSeries() { >+ return series; >+ } >+ >+ private void addStyle(CTScatterChart ctScatterChart) { >+ CTScatterStyle scatterStyle = ctScatterChart.addNewScatterStyle(); >+ scatterStyle.setVal(STScatterStyle.LINE_MARKER); >+ } >+} >diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java >new file mode 100644 >index 0000000..f019c4b >--- /dev/null >+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/charts/XSSFValueAxis.java >@@ -0,0 +1,127 @@ >+/* ==================================================================== >+ 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); >+ } >+ >+ @Override >+ public long getId() { >+ return ctValAx.getAxId().getVal(); >+ } >+ >+ @Override >+ public void setCrossBetween(AxisCrossBetween crossBetween) { >+ ctValAx.getCrossBetween().setVal(fromCrossBetween(crossBetween)); >+ } >+ >+ @Override >+ 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(); >+ } >+ >+ @Override >+ 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(); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 51196
:
26995
|
26996
|
27004
|
27021
|
27033
|
27039
|
27077
|
27294
|
27445