Here’s a simple sample to render a chart as an image to an ImageControl object in a dialog box
REM ***** BASIC *****
Private oDlg As Object
Private oImg As Object
Sub ShowDialog
DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oImg = oDlg.getControl("ImageControl1")
CenterDialog
ExportChartToImage
oDlg.execute()
oDlg.dispose()
End Sub
Sub CenterDialog
Dim oSize As New com.sun.star.awt.Size, factor As Double
Dim oCC, oComponentWindow, oTopWindowPosSize
oCC = ThisComponent.getCurrentController()
oComponentWindow = oCC.ComponentWindow
oTopWindowPosSize = oComponentWindow.Toolkit.ActiveTopWindow.getPosSize()
oSize.Width = oDlg.Model.Width
oSize.Height = oDlg.Model.Height
factor = oSize.Width / oDlg.convertSizeToPixel(oSize, com.sun.star.util.MeasureUnit.APPFONT).Width
With oDlg.Model
.PositionX = (factor * oTopWindowPosSize.Width - .Width) / 2
.PositionY = (factor * oTopWindowPosSize.Height - .Height) / 2
End With
End Sub
Sub ExportChartToImage
Dim oDoc As Object
Dim oDrawPage As Object
Dim oShape As Object
oDoc = ThisComponent
oDrawPage = oDoc.getSheets().getByIndex(0).getDrawPage()
oShape = oDrawPage.getByIndex(0)
If IsNull(oShape) Then Exit Sub
If Not IsNull(oShape.Graphic) Then
oImg.Model.Graphic = oShape.Graphic
End If
End Sub
ChartsToImage.ods (25.3 KB)