oCharts.addNewByName(PlotName, Rect, Source(), False, False)
oChart=oCharts.getByName(PlotName).EmbeddedObject
oDataSeries=oChart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0)
oChart.Diagram=oChart.createInstance("com.sun.star.chart.XYDiagram")
oCurve=oChart.createInstance ("com.sun.star.chart2.LinearRegressionCurve")
oDataSeries.addRegressionCurve(oCurve)
The last commend seems to crash the Libreoffice.
When starting the libreoffice, below messages appear on the shell terminal.
Gtk-Message: 19:33:54.208: GtkDialog mapped without a transient parent. This is discouraged.
Gtk-Message: 19:33:59.165: GtkDialog mapped without a transient parent. This is discouraged.
Gtk-Message: 19:40:25.365: GtkDialog mapped without a transient parent. This is discouraged.
The macro should be inside the below sheet:
XY_PLOT.ods (12.6 KB)
I think the latest version didn’t crash, but regression curve is not coming out.
REM ***** BASIC *****
REM XY PLOT for cell range B2:C11 filled with data as below (C=(B^2)/4 parabola)
REM PLOT APPEARS in cellrange F2:R46
REM B2:C2=1, 0.25
REM B3:C3=2, 1
REM ...
REM B10:C10=9, 20.25
REM B11:C11=10, 25
Sub PLOTXY
Dim Doc as Object
Dim oSheet as Object
Dim Flags as Long
Dim oTarget as Object
Dim DescriptX, DescriptY, Cell, oCharts, oChart As Object
Dim Rect As new com.sun.star.awt.Rectangle
Dim Source(1) As New com.sun.star.table.CellRangeAddress
Dim oLabelAll as new com.sun.star.chart2.DataPointLabel
Dim oDataSeries As Object
Dim oCurves, Ocurve as Object
Doc=ThisComponent
oSheet=Doc.CurrentController.ActiveSheet
xSheet=oSheet.getRangeAddress().Sheet
oLabelAll.ShowCategoryName = True
oLabelAll.ShowLegendSymbol = False
oLabelAll.ShowNumber = False
oLabelAll.ShowNumberInPercent = False
oCharts=oSheet.Charts
Rect.Width = 30000
Rect.Height = 20000
xCol=1
yCol=2
nRow=10
LTX=5
LTY=1
Rect.X = oSheet.getCellByPosition(LTX,LTY).Position.X
Rect.Y = oSheet.getCellByPosition(LTX,LTY).Position.Y
Source(0).Sheet = xSheet
Source(0).StartColumn = xCol
Source(0).StartRow = 1
Source(0).EndColumn = xCol
Source(0).EndRow = nRow
Source(1).Sheet = xSheet
Source(1).StartColumn = yCol
Source(1).StartRow = 1
Source(1).EndColumn = yCol
Source(1).EndRow = nRow
PlotName=oSheet.getCellByPosition(xCol,0).String+".Sheet"+Trim(Str(xSheet))+".0"
oCharts.addNewByName(PlotName, Rect, Source(), False, False)
oChart=oCharts.getByName(PlotName).EmbeddedObject
oDataSeries=oChart.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0)
oChart.Diagram=oChart.createInstance("com.sun.star.chart.XYDiagram")
REM The regression curve below seems hard case to get it working
oCurves=oDataSeries.getRegressionCurves()
oCurve=oChart.createInstance ("com.sun.star.chart2.LinearRegressionCurve")
oCurves.addRegressionCurve(oCurve)
End Sub