3-D Charts

From Apache OpenOffice Wiki
Jump to: navigation, search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.



Some chart types can display a 3-dimensional representation. To switch a chart to 3-dimensional, set the boolean property Dim3D of the service com.sun.star.chart.Dim3DDiagram.

In addition to this property, bar charts support a property called Deep (see service com.sun.star.chart.BarDiagram) that arranges the series of a bar chart along the z-axis, which in a chart, points away from the spectator. The service com.sun.star.chart.Chart3DBarProperties offers a property SolidType to set the style of the data point solids. The solid styles can be selected from cuboids, cylinders, cones, and pyramids with a square base (see constants in com.sun.star.chart.ChartSolidType).

The XDiagram of a 3-dimensional chart is also a scene object that supports modification of the rotation and light sources. The example below shows how to rotate the scene object and add another light source.

  // prerequisite: maDiagram contains a valid bar diagram
  // ...
  
  import com.sun.star.drawing.HomogenMatrix;
  import com.sun.star.drawing.HomogenMatrixLine;
  import com.sun.star.chart.X3DDisplay;
  import com.sun.star.beans.XPropertySet;
  
  XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, maDiagram);
  Boolean aTrue = new Boolean(true);
  
  aDiaProp.setPropertyValue("Dim3D", aTrue);
  aDiaProp.setPropertyValue("Deep", aTrue);
  
  // from service Chart3DBarProperties:
  aDiaProp.setPropertyValue("SolidType", new Integer(
      com.sun.star.chart.ChartSolidType.CYLINDER));
  
  // change floor color to Magenta6
  XPropertySet aFloor = ((X3DDisplay) UnoRuntime.queryInterface( 
      X3DDisplay.class, maDiagram)).getFloor();
  aFloor.setPropertyValue("FillColor", new Integer(0x6b2394));
  
  // rotate the scene using a homogen 4x4 matrix
  // -------------------------------------------
  HomogenMatrix aMatrix = new HomogenMatrix();
  // initialize matrix with identity
  HomogenMatrixLine aLines[] = new HomogenMatrixLine[] {
          new HomogenMatrixLine(1.0, 0.0, 0.0, 0.0),
          new HomogenMatrixLine(0.0, 1.0, 0.0, 0.0),
          new HomogenMatrixLine(0.0, 0.0, 1.0, 0.0),
          new HomogenMatrixLine(0.0, 0.0, 0.0, 1.0)
      };
  
  aMatrix.Line1 = aLines[0];
  aMatrix.Line2 = aLines[1];
  aMatrix.Line3 = aLines[2];
  aMatrix.Line4 = aLines[3];
  
  // rotate 10 degrees along the x axis
  double fAngle = 10.0;
  double fCosX = Math.cos(Math.toRadians(fAngle));
  double fSinX = Math.sin(Math.toRadians(fAngle));
  
  // rotate -20 degrees along the y axis
  fAngle = -20.0;
  double fCosY = Math.cos(Math.toRadians(fAngle));
  double fSinY = Math.sin(Math.toRadians(fAngle));
  
  // rotate -5 degrees along the z axis
  fAngle = -5.0;
  double fCosZ = Math.cos(Math.toRadians(fAngle));
  double fSinZ = Math.sin(Math.toRadians(fAngle));
  
  // set the matrix such that it represents all three rotations in the order
  // rotate around x axis then around y axis and finally around the z axis
  aMatrix.Line1.Column1 = fCosY * fCosZ;
  aMatrix.Line1.Column2 = fCosY * -fSinZ;
  aMatrix.Line1.Column3 = fSinY;
  
  aMatrix.Line2.Column1 = fSinX * fSinY * fCosZ + fCosX * fSinZ;
  aMatrix.Line2.Column2 = -fSinX * fSinY * fSinZ + fCosX * fCosZ;
  aMatrix.Line2.Column3 = -fSinX * fCosY;
  
  aMatrix.Line3.Column1 = -fCosX * fSinY * fCosZ + fSinX * fSinZ;
  aMatrix.Line3.Column2 = fCosX * fSinY * fSinZ + fSinX * fCosZ;
  aMatrix.Line3.Column3 = fCosX * fCosY;
  
  aDiaProp.setPropertyValue("D3DTransformMatrix", aMatrix);
  
  // add a red light source
  // ----------------------
  
  // in a chart by default only the second (non-specular) light source is switched on
  // light source 1 is the only specular light source that is used here
  
  // set direction
  com.sun.star.drawing.Direction3D aDirection = new com.sun.star.drawing.Direction3D();
  
  aDirection.DirectionX = -0.75;
  aDirection.DirectionY = 0.5;
  aDirection.DirectionZ = 0.5;
  
  aDiaProp.setPropertyValue("D3DSceneLightDirection1", aDirection);
  aDiaProp.setPropertyValue("D3DSceneLightColor1", new Integer(0xff3333));
  aDiaProp.setPropertyValue("D3DSceneLightOn1", new Boolean(true));

Refer to Drawing Documents and Presentation Documents for additional details about three-dimensional properties.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages