21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9<br />

C H A P T E R 9<br />

9 Charts (Diagrams)<br />

<strong>OpenOffice</strong>.<strong>org</strong> can display data as a chart, which creates graphical representations of numerical data in the form<br />

of bars, pie charts, lines or other elements. Data can either be displayed as 2D or 3D graphics, and the appearance<br />

of the chart elements can be individually adapted in a way similar to the process used for drawing elements.<br />

Charts are not treated as independent documents in <strong>OpenOffice</strong>.<strong>org</strong>, but as objects that are embedded in an<br />

existing document.<br />

A chart may contain its own data or may display data from the container document. For example charts in<br />

spreadsheets can display data obtained from the cell ranges and charts in text documents can display data obtained<br />

from writer tables.<br />

Using Charts in Spreadsheets<br />

Charts within spreadsheets can display the data from an assigned cell range within the spreadsheet. Any<br />

modifications made to the data within the spreadsheet will also be reflected in the assigned chart. The following<br />

example shows how to create a chart assigned to some cell ranges within a spreadsheet document:<br />

Dim Doc As Object<br />

Dim Charts As Object<br />

Dim Chart as Object<br />

Dim Rect As New com.sun.star.awt.Rectangle<br />

Dim RangeAddress(0) As New com.sun.star.table.CellRangeAddress<br />

Doc = ThisComponent<br />

Charts = Doc.Sheets(0).Charts<br />

Rect.X = 8000<br />

Rect.Y = 1000<br />

Rect.Width = 10000<br />

Rect.Height = 7000<br />

RangeAddress(0).Sheet = 0<br />

RangeAddress(0).StartColumn = 0<br />

RangeAddress(0).StartRow = 0<br />

RangeAddress(0).EndColumn = 2<br />

RangeAddress(0).EndRow = 12<br />

Charts.addNewByName("MyChart", Rect, RangeAddress(), True, True)<br />

Although the code used in the example may appear to be complex, the central processes are limited to three lines.<br />

The first central line creates the Doc document variable, which references the current spreadsheet document (Doc<br />

line = StarDesktop.CurrentComponent). The code used in the example then creates a list containing all charts<br />

of the first spreadsheet (Charts line = Doc.Sheets(0).Charts). Finally, in the last line, a new chart is added to<br />

this list using the addNewByName method. This new chart is then visible to the user. The variable RangeAddress<br />

determines the assigned cell range whose data will be displayed within the chart. The variable Rect determines the<br />

position and size of the chart within the first sheet in the spreadsheet document.<br />

131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!