git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1842876 13f79535-47bb-0310-9956-ffa450edef68tags/REL_4_0_1
series2.setTitle(series[1], chart.setSheetTitle(series[1], 1)); | series2.setTitle(series[1], chart.setSheetTitle(series[1], 1)); | ||||
chart.plot(bar); | chart.plot(bar); | ||||
chart.setTitleText(chartTitle); // https://stackoverflow.com/questions/30532612 | |||||
// chart.setTitleOverlay(overlay); | |||||
} | } | ||||
private static void setColumnData(XSLFChart chart, String chartTitle) { | private static void setColumnData(XSLFChart chart, String chartTitle) { |
// Use a category axis for the bottom axis. | // Use a category axis for the bottom axis. | ||||
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM); | XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM); | ||||
bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765 | |||||
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | ||||
leftAxis.setTitle("f(x)"); | |||||
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | ||||
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); | XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); |
// Use a category axis for the bottom axis. | // Use a category axis for the bottom axis. | ||||
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM); | XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM); | ||||
bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765 | |||||
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | ||||
leftAxis.setTitle("f(x)"); | |||||
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | ||||
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); | XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); |
legend.setPosition(LegendPosition.TOP_RIGHT); | legend.setPosition(LegendPosition.TOP_RIGHT); | ||||
XDDFValueAxis bottomAxis = chart.createValueAxis(AxisPosition.BOTTOM); | XDDFValueAxis bottomAxis = chart.createValueAxis(AxisPosition.BOTTOM); | ||||
bottomAxis.setTitle("x"); // https://stackoverflow.com/questions/32010765 | |||||
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT); | ||||
leftAxis.setTitle("f(x)"); | |||||
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); | ||||
XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); | XDDFDataSource<Double> xs = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1)); |
series2.setTitle(series[1], chart.setSheetTitle(series[1], 1)); | series2.setTitle(series[1], chart.setSheetTitle(series[1], 1)); | ||||
chart.plot(bar); | chart.plot(bar); | ||||
chart.setTitleText(chartTitle); // https://stackoverflow.com/questions/30532612 | |||||
// chart.setTitleOverlay(overlay); | |||||
} | } | ||||
private static void setColumnData(XWPFChart chart, String chartTitle) { | private static void setColumnData(XWPFChart chart, String chartTitle) { |
return new XDDFShapeProperties(properties); | return new XDDFShapeProperties(properties); | ||||
} | } | ||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
@Override | |||||
public void setTitle(String text) { | |||||
if (!ctCatAx.isSetTitle()) { | |||||
ctCatAx.addNewTitle(); | |||||
} | |||||
XDDFTitle title = new XDDFTitle(null, ctCatAx.getTitle()); | |||||
title.setOverlay(false); | |||||
title.setText(text); | |||||
} | |||||
@Override | @Override | ||||
public boolean isSetMinorUnit() { | public boolean isSetMinorUnit() { | ||||
return false; | return false; |
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx; | import org.openxmlformats.schemas.drawingml.x2006.chart.CTSerAx; | ||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface; | import org.openxmlformats.schemas.drawingml.x2006.chart.CTSurface; | ||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; | import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; | ||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx; | |||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; | import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx; | ||||
import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; | import org.openxmlformats.schemas.drawingml.x2006.chart.ChartSpaceDocument; | ||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; | import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties; | ||||
if (!chart.isSetTitle()) { | if (!chart.isSetTitle()) { | ||||
chart.addNewTitle(); | chart.addNewTitle(); | ||||
} | } | ||||
CTTitle title = chart.getTitle(); | |||||
if (title.isSetOverlay()) { | |||||
title.getOverlay().setVal(overlay); | |||||
new XDDFTitle(this, chart.getTitle()).setOverlay(overlay); | |||||
} | |||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
public void setTitleText(String text) { | |||||
if (!chart.isSetTitle()) { | |||||
chart.addNewTitle(); | |||||
} | |||||
new XDDFTitle(this, chart.getTitle()).setText(text); | |||||
} | |||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
public XDDFTitle getTitle() { | |||||
if (chart.isSetTitle()) { | |||||
return new XDDFTitle(this, chart.getTitle()); | |||||
} else { | } else { | ||||
title.addNewOverlay().setVal(overlay); | |||||
return null; | |||||
} | } | ||||
} | } | ||||
if (!chart.isSetTitle()) { | if (!chart.isSetTitle()) { | ||||
return null; | return null; | ||||
} | } | ||||
CTTitle title = chart.getTitle(); | |||||
if (!title.isSetTx()) { | |||||
return null; | |||||
} | |||||
CTTx tx = title.getTx(); | |||||
if (!tx.isSetRich()) { | |||||
return null; | |||||
} | |||||
return new XDDFTextBody(this, tx.getRich()); | |||||
return new XDDFTitle(this, chart.getTitle()).getBody(); | |||||
} | } | ||||
@Override | @Override |
public abstract XDDFShapeProperties getOrAddMinorGridProperties(); | public abstract XDDFShapeProperties getOrAddMinorGridProperties(); | ||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
public abstract void setTitle(String text); | |||||
/** | /** | ||||
* @return true if minor unit value is defined, false otherwise | * @return true if minor unit value is defined, false otherwise | ||||
*/ | */ |
/* | |||||
* ==================================================================== | |||||
* 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.xddf.usermodel.chart; | |||||
import org.apache.poi.util.Beta; | |||||
import org.apache.poi.xddf.usermodel.text.TextContainer; | |||||
import org.apache.poi.xddf.usermodel.text.XDDFTextBody; | |||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle; | |||||
import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx; | |||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
@Beta | |||||
public class XDDFTitle { | |||||
private final CTTitle title; | |||||
private final TextContainer parent; | |||||
public XDDFTitle(TextContainer parent, CTTitle title) { | |||||
this.parent = parent; | |||||
this.title = title; | |||||
} | |||||
public XDDFTextBody getBody() { | |||||
XDDFTextBody body; | |||||
if (title.isSetTxPr()) { | |||||
body = new XDDFTextBody(parent, title.getTxPr()); | |||||
} else { | |||||
if (!title.isSetTx()) { | |||||
title.addNewTx(); | |||||
} | |||||
CTTx tx = title.getTx(); | |||||
if (!tx.isSetRich()) { | |||||
tx.addNewRich(); | |||||
} | |||||
body = new XDDFTextBody(parent, tx.getRich()); | |||||
} | |||||
return body; | |||||
} | |||||
public void setText(String text) { | |||||
if (!title.isSetLayout()) { | |||||
title.addNewLayout(); | |||||
} | |||||
getBody().setText(text); | |||||
} | |||||
public void setOverlay(Boolean overlay) { | |||||
if (overlay == null) { | |||||
if (title.isSetOverlay()) { | |||||
title.unsetOverlay(); | |||||
} | |||||
} else { | |||||
if (title.isSetOverlay()) { | |||||
title.getOverlay().setVal(overlay); | |||||
} else { | |||||
title.addNewOverlay().setVal(overlay); | |||||
} | |||||
} | |||||
} | |||||
} |
return new XDDFShapeProperties(properties); | return new XDDFShapeProperties(properties); | ||||
} | } | ||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
@Override | |||||
public void setTitle(String text) { | |||||
if (!ctValAx.isSetTitle()) { | |||||
ctValAx.addNewTitle(); | |||||
} | |||||
XDDFTitle title = new XDDFTitle(null, ctValAx.getTitle()); | |||||
title.setOverlay(false); | |||||
title.setText(text); | |||||
} | |||||
@Override | @Override | ||||
public boolean isSetMinorUnit() { | public boolean isSetMinorUnit() { | ||||
return ctValAx.isSetMinorUnit(); | return ctValAx.isSetMinorUnit(); |
} | } | ||||
} | } | ||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
public XDDFRunProperties addDefaultRunProperties() { | |||||
if (!props.isSetDefRPr()) { | |||||
props.addNewDefRPr(); | |||||
} | |||||
return getDefaultRunProperties(); | |||||
} | |||||
public XDDFRunProperties getDefaultRunProperties() { | public XDDFRunProperties getDefaultRunProperties() { | ||||
if (props.isSetDefRPr()) { | if (props.isSetDefRPr()) { | ||||
return new XDDFRunProperties(props.getDefRPr()); | return new XDDFRunProperties(props.getDefRPr()); |
return p; | return p; | ||||
} | } | ||||
public void setText(String text) { | |||||
if (_body.sizeOfPArray() > 0) { | |||||
// remove all but first paragraph | |||||
for (int i = _body.sizeOfPArray() - 1; i > 0; i--) { | |||||
_body.removeP(i); | |||||
} | |||||
getParagraph(0).setText(text); | |||||
} else { | |||||
// as there were no paragraphs yet, initialize the text body | |||||
initialize().setText(text); | |||||
} | |||||
} | |||||
public XDDFTextParagraph addNewParagraph() { | public XDDFTextParagraph addNewParagraph() { | ||||
return new XDDFTextParagraph(_body.addNewP(), this); | return new XDDFTextParagraph(_body.addNewP(), this); | ||||
} | } |
_runs.add(new XDDFTextRun((CTRegularTextRun) xo, this)); | _runs.add(new XDDFTextRun((CTRegularTextRun) xo, this)); | ||||
} | } | ||||
} | } | ||||
addDefaultRunProperties(); | |||||
addAfterLastRunProperties(); | |||||
} | |||||
public void setText(String text) { | |||||
// remove all runs | |||||
for (int i = _p.sizeOfBrArray() - 1; i >= 0; i--) { | |||||
_p.removeBr(i); | |||||
} | |||||
for (int i = _p.sizeOfFldArray() - 1; i >= 0; i--) { | |||||
_p.removeFld(i); | |||||
} | |||||
for (int i = _p.sizeOfRArray() - 1; i >= 0; i--) { | |||||
_p.removeR(i); | |||||
} | |||||
_runs.clear(); | |||||
appendRegularRun(text); | |||||
} | } | ||||
public String getText() { | public String getText() { | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @since 4.0.1 | |||||
*/ | |||||
public XDDFRunProperties addDefaultRunProperties() { | |||||
return getOrCreateProperties().addDefaultRunProperties(); | |||||
} | |||||
public XDDFRunProperties getDefaultRunProperties() { | public XDDFRunProperties getDefaultRunProperties() { | ||||
if (_p.isSetPPr()) { | if (_p.isSetPPr()) { | ||||
return getProperties().getDefaultRunProperties(); | return getProperties().getDefaultRunProperties(); |