Macro basic XYDiagram with regression line

My script makes only points with line. Instead of this standard line I want to have points with regression line.


ChartNo = 1
sName = "test_" + str(ChartNo)
sDataRng = "A10:B20"
SheetForRectangle = ThisComponent.Sheets.getByName("Rectangle")
ChartsForTest = SheetForRectangle.getCharts()
AddressForCells = SheetForRectangle.getCellRangeByName( sDataRng ).getRangeAddress()

If ChartsForTest.hasByName(sName) Then
End If

If NOT ChartsForTest.hasByName(sName) Then
	RectForTest = createObject("")
	RectForTest.X = 10000
	RectForTest.Y = 10000
	RectForTest.width = 20000
	RectForTest.Height= 10000
	ChartsForTest.addNewByName(sName, RectForTest, Array(AddressForCells), False, True)
End If

ChartForTest = ChartsForTest.getByName( sName )  
oChartDoc = ChartForTest.getEmbeddedObject()
oTitle = oChartDoc.getTitle()  
oTitle.String = "Some title"

oChartDoc.HasLegend = 1
LegendForTest = oChartDoc.Legend
oChartDoc.Legend.Alignment = 
oChartDoc.Legend.FillStyle =
oChartDoc.Legend.FillColor = RGB(210, 210, 210)
oChartDoc.Legend.LineColor = RGB(50, 0, 0)
oChartDoc.Legend.CharHeight = 7

oDiagram = oChartDoc.createInstance( "" )
oDiagram = oChartDoc.getDiagram()

oDiagram.Lines = True
oDiagram.SymbolType = -10

oDiagram.HasXAxisTitle = True
oDiagram.XAxisTitle.String ="Some X-Axis"

oDiagram.HasYAxisTitle = True
oDiagram.YAxisTitle.String ="Some Y-Axis"

oDiagram.RegressionCurves =
oDiagram.DataRowSource =


What I do wrong? Why it is going without regression line?

I cannot tell. But there must be a misunderstanding: An X-Y-Diagram can contain many DataSeries, and for each one the TrendLine can be set and formatted independently. There must be a property of the chart containing respective information for the many series one by one. The .RegressionCurves cannot do that due to its type.
Probably the XRay tool or the MRT tool can help.

Thank you. Below is the answer from Jim K.

Regression curves must be added to a specific data series.

Sub AddRegressionCurve
  oCharts = ThisComponent.getSheets().getByIndex(0).getCharts()
  oEmbeddedObject = oCharts.getByIndex(0).getEmbeddedObject()
  oDataSeries = oEmbeddedObject.FirstDiagram.CoordinateSystems(0).ChartTypes(0).DataSeries(0)
  curves = oDataSeries.getRegressionCurves()
  curve = CreateUnoService("")
End Sub

Thank you very much for answer and links :slight_smile: