altrent General User

Joined: 08 Aug 2005 Posts: 5
|
Posted: Fri Aug 19, 2005 9:40 am Post subject: [java] Update pie chart data embedded in writer |
|
|
Hi,
I know this post is really old, but since I spent quite a fair amount of time on the same topic I wanted to share with others how to update the data of an already existing pie chart embedded in a writer document.
| Code: |
private void updatePie(XTextDocument myDoc) {
XTextEmbeddedObjectsSupplier xTextEmbeddedObjectsSupplier =
(XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface(
XTextEmbeddedObjectsSupplier.class,
myDoc);
XNameAccess xName = (XNameAccess) UnoRuntime.queryInterface(
XNameAccess.class,
xTextEmbeddedObjectsSupplier.getEmbeddedObjects());
try {
XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class,
xName.getByName("mypie" )); // put the name of your pie chart
XChartDocument aResult = (XChartDocument) UnoRuntime.queryInterface(
XChartDocument.class,
xPropSet.getPropertyValue( "Model" ));
XChartDataArray aDataArray = (XChartDataArray)
UnoRuntime.queryInterface(XChartDataArray.class,
aResult.getData());
int num = 5;
String[] description = {"Kate", "Bruce", "Ian", "Charlie", "Kilian"};
double[] m = {10.0, 15.0, 5.0, 8.0, 62.0};
double[][] data = new double[num][1];
XDiagram diagram = aResult.getDiagram();
for(int i = 0; i < data.length; i++ ) { //4
for (int j = 0; j<data[i].length; j++) { //1
data[i][j] = m[i];
}
}
aDataArray.setData(data);
aDataArray.setRowDescriptions(description);
for(int i = 0; i < data.length; i++ ) { //4
for (int j = 0; j<data[i].length; j++) { //1
XPropertySet ptProp = diagram.getDataPointProperties(i, j);
ptProp.setPropertyValue("CharHeight", new Float(8.0));
ptProp.setPropertyValue("CharColor", new Integer( 0x993366 ));
}
}
} catch(com.sun.star.container.NoSuchElementException x) {
x.printStackTrace();
} catch(com.sun.star.lang.WrappedTargetException wx) {
wx.printStackTrace();
} catch (com.sun.star.beans.UnknownPropertyException ux) {
ux.printStackTrace();
} catch (com.sun.star.lang.IndexOutOfBoundsException iobx) {
iobx.printStackTrace();
} catch (com.sun.star.beans.PropertyVetoException pvx) {
pvx.printStackTrace();
} catch (com.sun.star.lang.IllegalArgumentException iax) {
iax.printStackTrace();
}
}
|
|
|