Common Parts of all Chart Types

From Apache OpenOffice Wiki
Jump to: navigation, search


The diagram object is an important object of a chart document. The diagram represents the visualization of the underlying data. The diagram object is a graphic object group that lies on the same level as the titles and the legend. From the diagram, data rows and data points are obtain that are also graphic objects that represent the respective data. Several properties can be set at a diagram to influence its appearance. Note that the term data series is used instead of data rows.

Some diagrams support the service that contains the property Dim3D. If this is set to true, you get a three-dimensional view of the chart, which in Apache OpenOffice is usually rendered in OpenGL. In 3-D charts, you can access the z-axis, which is not available in 2-D.

The service offers the properties Percent and Stacked. With these properties, accumulated values can be stacked for viewing. When setting Percent to true, all slices through the series are summed up to 100 percent, so that for an AreaDiagram the whole diagram space would be filled with the series. Note that setting the Percent property also sets the Stacked property, because Percent is an addition to Stacked.

There is a third service that extends a base diagram type for displaying statistical elements called With this service, error indicators or a mean value line are added. The mean value line represents the mean of all values of a series. The regression curve is only available for the XYDiagram, because a numeric x-axis, is required.


The illustration above shows that there are eight base types of diagrams. The three services, StackableDiagram, Dim3DDiagram and ChartStatistics are also supported for several diagram types and allows extensions of the base types as discussed. For instance, a three-dimensional pie chart can be created, because the service points to the service.

The services,, and support all three feature services.


All charts can have one or more axis, except for pie charts. A typical two-dimensional chart has two axis, an x- and y-axis. Secondary x- or y-axis can be added to have up to four axis. In a three-dimensional chart, there are typically three axis, x-, y- and z-axis. There are no secondary axis in 3-dimensional charts.

An axis combines two types of properties:

  • Scaling properties that affect other objects in the chart. A minimum and maximum values are set that spans the visible area for the displayed data. A step value can also be set that determines the distance between two tick-marks, and the distance between two grid-lines if grids are switched on for the corresponding axis.
  • Graphical properties that influence the visual impression. These are character properties (see affecting the labels and line properties (see that are applied to the axis line and the tick-marks.

Different diagram types support a different number of axis. In the above illustration, a, also known as a scatter diagram, is shown. The scatter diagram supports x- and y-axis, but not a z-axis as there is no 3-dimensional mode. The supports no axis at all. The supports all kinds of axis. Note that the z-Axis is only supported in a three-dimensional chart. Note that there is a that includes the and is supported by all diagrams in required to support the service ChartAxisXSupplier.

The following example shows how to obtain an axis and how to change the number format.

  // class members
  XChartDocument aChartDocument;
  XDiagram aDiagram;
  // get an XChartDocument and assign it to aChartDocument
  // get the diagram from the document and assign it to aDiagram
  // ...
  // check whether the current chart supports a y-axis
  XAxisYSupplier aYAxisSupplier = (XAxisYSupplier) UnoRuntime.queryInterface(
      XAxisYSupplier.class, aDiagram);
  if (aYAxisSupplier != null) {
      XPropertySet aAxisProp = aYAxisSupplier.getYAxis();
      // initialize new format with value for standard
      int nNewNumberFormat = 0;
      XNumberFormatsSupplier aNumFmtSupp = (XNumberFormatsSupplier)
      if (aNumFmtSupp != null) {
 aFormats = aNumFmtSupp.getNumberFormats();
          Locale aLocale = new Locale("de", "DE", "de");
          String aFormatStr = aFormats.generateFormat(
              0,        // base key
              aLocale,  // locale
              true,     // thousands separator on
              true,     // negative values in red
              (short)3, // number of decimal places
              (short)1  // number of leading ciphers
          nNewNumberFormat = aFormats.addNew(aFormatStr, aLocale);
      aAxisProp.setPropertyValue("NumberFormat", new Integer(nNewNumberFormat));

Data Series and Data Points

The objects that visualize the actual data are data series. The API calls them data rows that are not rows in a two-dimensional spreadsheet table, but as sets of data, because the data for a data row can reside in a column of a spreadsheet table.

The data rows contain data points. The following two methods at the interface allow changes to the properties of a whole series or single data point:

  com::sun::star::beans::XPropertySet getDataRowProperties( [in] long nRow)
  com::sun::star::beans::XPropertySet getDataPointProperties( [in] long nCol,
                                                              [in] long nRow)

The index provided in these methods is 0-based, that is, 0 is the first series. In XYDiagrams, the first series has an index 1, because the first array of values contains the x-values of the diagram that is not visualized. This behavior exists for historical reasons.

In a spreadsheet context, the indexes for getDataPointProperties() are called nCol and nRow and are misleading. The nRow parameter gives the data row, that is, the series index. The nCol gives the index of the data point inside the series, regardless if the series is taken from rows or columns in the underlying table. To get the sixth point of the third series, write getDataPointProperties(5, 2).

Data rows and data points have and They also support for text descriptions that can be displayed next to data points.

Properties can be set for symbols and the type of descriptive text desired. With the SymbolType property, one of several predefined symbols can be set. With SymbolBitmapURL, a URL that points to a graphic in a format known by Apache OpenOffice can be set that is then used as a symbol in a or

The following example demonstrates how to set properties of a data point. Before implementing this example, create a chart document and diagram of the type XYDiagram. aChartDocument; aXYDiagram;
  // get a chart document and assign it to aChartDocument
  // set an "XYDiagram" and remember the diagram in aXYDiagram
  // ...
  // get the properties of the fifth data point of the first series
  // note that index 1 is the first series only in XYDiagrams
  try { aPointProp = maDiagram.getDataPointProperties(4, 1);
  } catch ( ex) {
      System.out.println("Index is out of bounds: " + ex);
  try {
      // set a bitmap via URL as symbol for the first series
      aPointProp.setPropertyValue("SymbolType", new Integer(ChartSymbolType.BITMAPURL));
      // add a label text with bold font, bordeaux red 14pt
      aPointProp.setPropertyValue("DataCaption", new Integer(ChartDataCaption.VALUE));
      aPointProp.setPropertyValue("CharHeight", new Float(14.0));
      aPointProp.setPropertyValue("CharColor", new Integer(0x993366));
      aPointProp.setPropertyValue("CharWeight", new Float(FontWeight.BOLD));
  } catch ( ex) {
      System.out.println("Exception caught: " + ex);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages