Move Diagram in Calc via Basic Macro

Is there a way to move a diagram in a calc sheet with a basic macro? I need to modify the position of two diagrams according to a specific condition (if one cell is < 0 or not).

If found the code to iterate over the diagrams, but I have no clue how to differentiate between them, although I have set their names in Calc. Also I need to know how to actually move them.

Alternatively I could also modify one diagram in terms of style (bars vs pie) and data source, if that would be possible.

Ok, I found it myself, at least I found ‘A’ way. Maybe there is a better one.

To position a Chart in a spreadsheet, you have to get its DrawPage:

doc = ThisComponent
sheet = doc.Sheets.getByName("mySheet")
container = sheet.getDrawPage.getByIndex(0)   'this gets you the first diagrams container'
diagramLocation = New com.sun.star.awt.Point
diagramLocation.X=1000                        'position and size measurement in 1/100 mm'
diagramLocation.Y=2000
container.setPosition(diagramLocation)

diagramSize = New com.sun.star.awt.Size
diagramSize.width=20000                       'so this will be 20x9 cm'
diagramSize.height=9000	
container.setSize(diagramSize)

chart = sheet.Charts.getByIndex(0).embeddedObject
'chart now gives you access to e.g. the diagram, the (sub)title, the legend, etc.