Documentation/BASIC Guide/Charts in Spreadsheets
Using Charts in Spreadsheets
Charts are not treated as independent documents in Apache OpenOffice, but as objects that are embedded in an existing document.
While charts in text and drawing documents remain isolated from the content of the document, when used in spreadsheet documents, a mechanism is provided which allows a link to be established between the document data and embedded charts. The following example explains the interaction between spreadsheet document and chart:
Dim Doc As Object Dim Charts As Object Dim Chart as Object Dim Rect As New com.sun.star.awt.Rectangle Dim RangeAddress(0) As New com.sun.star.table.CellRangeAddress Doc = StarDesktop.CurrentComponent Charts = Doc.Sheets(0).Charts Rect.X = 8000 Rect.Y = 1000 Rect.Width = 10000 Rect.Height = 7000 RangeAddress(0).Sheet = 0 RangeAddress(0).StartColumn = 0 RangeAddress(0).StartRow = 0 RangeAddress(0).EndColumn = 2 RangeAddress(0).EndRow = 12 Charts.addNewByName("MyChart", Rect, RangeAddress(), True, True)
Although the code used in the example may appear to be complex, the central processes are limited to three lines: the first central line creates the Doc document variable, which references the current spreadsheet document (Doc line = StarDesktop.CurrentComponent). The code used in the example then creates a list containing all charts of the first spreadsheet (Charts line = Doc.Sheets(0).Charts). Finally, a new chart is added to the last line of this list using the addNewByName method. This new chart is then visible to the user.
The last line initializes the Rect and RangeAddress auxiliary structures, which the addNewByName method also provides as a parameter. Rect determines the position of the chart within the spreadsheet. RangeAddress determines the range whose data is to be linked to the chart.
The previous example creates a bar chart. If a different type of graphic is needed, then the bar chart must be explicitly replaced:
Chart = Charts.getByName("MyChart").embeddedObject Chart.Diagram = Chart.createInstance("com.sun.star.chart.LineDiagram")
The first lines defines the corresponding chart object. The second line replaces the current chart with a new one — in this example, a line chart.
|Content on this page is licensed under the Public Documentation License (PDL).|