XMultiServiceFactory.class, xChartDoc);
aDiagram = (XDiagram) UnoRuntime.queryInterface(
XDiagram.class,
chartMSF.createInstance("com.sun.star.chart.XYDiagram"));
// if x or y values are not dimensionless, then set titles
XShape yTitleShape = ((XAxisYSupplier) UnoRuntime.queryInterface(XAxisYSupplier.class, aDiagram))
.getYAxisTitle();
XShape xTitleShape = ((XAxisXSupplier) UnoRuntime.queryInterface(XAxisXSupplier.class, aDiagram))
.getXAxisTitle();
if (xEvalUnit.getName()!=null){
((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aDiagram))
.setPropertyValue("HasXAxisTitle", true);
((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTitleShape))
.setPropertyValue("String", "["+xEvalUnit.getName()+"]");
}
if (yEvalUnit.getName()!=null){
((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aDiagram))
.setPropertyValue("HasYAxisTitle", true);
((XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, yTitleShape))
.setPropertyValue("String", "["+yEvalUnit.getName()+"]");
}
/* Default to no points */
XPropertySet chartXPS = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class,aDiagram);
/* Fix formatting so it looks good (X and Y Grid,
* no markers by default) */
chartXPS.setPropertyValue("SymbolType", ChartSymbolType.NONE);
chartXPS.setPropertyValue("HasYAxisGrid",false);
xChartDoc.setDiagram(aDiagram);
// set xaxis to cross y-axis at minimum value
((XAxisXSupplier) UnoRuntime.queryInterface(XAxisXSupplier.class, aDiagram))
.getXAxis()
.setPropertyValue("CrossoverPosition",ChartAxisPosition.START );
// set xaxis to cross y-axis at minimum value
((XAxisYSupplier) UnoRuntime.queryInterface(XAxisYSupplier.class, aDiagram))
.getYAxis()
.setPropertyValue("CrossoverPosition",ChartAxisPosition.START );
long legendWidth = xChartDoc.getLegend().getSize().Width
+ yTitleShape.getSize().Width
+ yTitleShape.getPosition().X + 6000;
// Must convert Long to Any to do setProperty
xFrameProps.setPropertyValue("Width", new Any(Type.LONG,legendWidth));
Integer xTitleHeight;
if (xTitleShape.getPosition().Y==0){
xTitleHeight = 0;
}
else{
// I think Y position will be distance to the top corner,
// so I do not also need the height of the XTitleShape.
xTitleHeight = (Integer)xFrameProps.getPropertyValue("Height")
- xTitleShape.getPosition().Y;
}
xFrameProps.setPropertyValue("Height",
xTitleHeight+ 6000);
}