How can I create an XY chart from a macro where each "Y" data value has
its own "X" data value. I know how to do this by hand because I can
individually specify these using the GUI. I can not, do this using a macro.
I know how to create an XY chart where every line uses the same X
values. For example:
Sub CreateChart
Dim oSheet 'Sheet containing the chart
Dim oRect 'How big is the chart
Dim oCharts 'Charts in the sheet
Dim oChart 'Created chart
Dim oAddress 'Address of data to plot
Dim sName$ 'Chart name
Dim oChartDoc 'Embedded chart object
Dim oTitle 'Chart title object
Dim oDiagram 'Inserted diagram (data).
Dim sDataRng$ 'Where is the data
sName = "ADP_Chart"
sDataRng = "A1:D6"
'sDataRng = "A33:D38"
oSheet = ThisComponent.sheets(0)
oAddress = oSheet.getCellRangeByName( sDataRng ).getRangeAddress()
oCharts = oSheet.getCharts()
If NOT oCharts.hasByName(sName) Then
oRect = createObject("com.sun.star.awt.Rectangle")
oRect.X = 10000
oRect.Y = 1000
oRect.width = 10000
oRect.Height= 10000
' The rectangle identifies the dimensions in 1/100 mm.
' The address is the location of the data.
' True indicates that column headings should be used.
' False indicates that Row headings should not be used.
oCharts.addNewByName(sName, oRect, Array(oAddress), True, False)
End If
oChart = oCharts.getByName( sName )
oChart.setRanges(Array(oAddress))
oChartDoc = oChart.getEmbeddedObject()
'oChartDoc.attachData(oAddress)
oTitle = oChartDoc.getTitle()
oTitle.String = "Andy - " & Now
' Create a diagram.
'oDiagram = oChartDoc.createInstance( "com.sun.star.chart.LineDiagram" )
oDiagram = oChartDoc.createInstance( "com.sun.star.chart.XYDiagram" )
oChartDoc.setDiagram( oDiagram )
oDiagram = oChartDoc.getDiagram()
oDiagram.DataCaption = com.sun.star.chart.ChartDataCaption.VALUE
oDiagram.DataRowSource = com.sun.star.chart.ChartDataRowSource.COLUMNS
End Sub
I can inspect the used ranges as follows:
Sub InspectChart
Dim oSheet 'Sheet containing the chart
Dim oCharts 'Charts in the sheet
Dim oChart 'Created chart
Dim sName$ 'Chart name
Dim oTitle 'Chart title object
Dim oDiagram 'Inserted diagram (data).
sName = "ADP_Chart"
oSheet = ThisComponent.sheets(0)
oCharts = oSheet.getCharts()
If NOT oCharts.hasByName(sName) Then
Exit Sub
End If
Dim oRanges
Dim i%
Dim s$
Dim oConv
oConv =
ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
oChart = oCharts.getByName( sName )
oRanges = oChart.getRanges()
s = ""
For i = LBound(oRanges) To UBound(oRanges)
oConv.Address = oRanges(i)
s = s & oConv.UserInterfaceRepresentation & CHR$(10)
' s = s & oConv.PersistentRepresentation & CHR$(10)
Next
MsgBox s
End Sub
Even if a range has its own X range, this is not shown in the range.
Also, I can use oChart.setRanges() to set multiple ranges, but this sets
them all to use the same x-range.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]