Setting the Chart Type

From Apache OpenOffice Wiki
Jump to: navigation, search

The default when creating a chart is a bar diagram with vertical bars. If a different chart type is required, apply a different diagram type to this initial chart. For example, to create a pie chart, insert the default bar chart and change it to a pie chart.

To change the type of a chart, create an instance of the required diagram service by its service name using the service factory provided by the This interface is available at the chart document model. After this service instance is created, set it using the setDiagram() method of the chart document.

In the following example, we change the chart type to a, also known as a scatter chart. We have assumed that there is a chart document in the variable aChartDoc already. The previous sections described how to create a document.

  // let aChartDoc be a valid XChartDocument
  // get the factory that can create diagrams
  XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime.queryInterface(
      XMultiServiceFactory.class, aChartDoc);
  XDiagram aDiagram = (XDiagram) UnoRuntime.queryInterface(
      XDiagram.class, aFact.createInstance(""));
  // now we have an xy-chart

Diagram Service Names since OOo 3.2 since OOo 3.2
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages