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 com.sun.star.chart.XChartDocument. 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 com.sun.star.chart.XYDiagram, 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("com.sun.star.chart.XYDiagram"));
 
  aChartDoc.setDiagram(aDiagram);
 
  // now we have an xy-chart


Diagram Service Names
com.sun.star.chart.BarDiagram
com.sun.star.chart.AreaDiagram
com.sun.star.chart.LineDiagram
com.sun.star.chart.PieDiagram
com.sun.star.chart.DonutDiagram
com.sun.star.chart.NetDiagram
com.sun.star.chart.XYDiagram
com.sun.star.chart.StockDiagram
com.sun.star.chart.BubbleDiagram since OOo 3.2
com.sun.star.chart.FilledNetDiagram since OOo 3.2
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages