For those about to play with charts

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)

1 Like

Here’s a slightly more advanced tuning with interactive grid control object
USE: From the menu bar, select ChartDialog > OpenDialog. Double-click on any
numeric value in the grid, type some new value, and press Enter…Wait a moment and see
InteractveGridWithChartToImage.ods (22.2 KB)

Näyttökuva 2026-02-14 223447

OK

What is your OS?

Linux (Debian Trixie)

Can’t you see the chart?

No chart. Just an empty spreadsheet window and a dialog with a table control.
And I have to kill the app because the modal dialog does not close.

Here :ok:
LO 7.3.7.2
OS Mint 21.3
 
Screenshot from 2026-02-14 18-18-08

Chart_Test_Save_To_File.ods (25.6 KB)

Doesn’t this work either?

Shows a dialog without table control but with the chart.

P.S. I run the early adopter release:
Version: 26.2.0.2 (X86_64)
Build ID: 750d5fef117734aeeb00d37a069d6c814e9eb8ce
CPU threads: 4; OS: Linux 6.12; UI render: default; VCL: x11
Locale: de-DE (de_DE.UTF-8); UI: en-US
Calc: threaded

I waited more than a moment and didn’t notice any change. The image will only update when I double-click on the new value again and press Enter.

(I am on Windows 11, tested with 25.2.4.3, 25.8.4.2 and 26.2.0.3).

I made the last example without the Grid control object so you could test if the chart works at all.

I have Microsoft Windows 11 Pro [Version 10.0.26100.7840] and everything works like a charm
LO: Version: 25.2.4.3 (X86_64) / LibreOffice Community
Build ID: 33e196637044ead23f5c3226cde09b47731f7e27
CPU threads: 4; OS: Windows 11 X86_64 (10.0 build 26100); UI render: Skia/Raster; VCL: win
Locale: fi-FI (fi_FI); UI: fi-FI
Calc: CL threaded

Yes, it works for me.


Here is a .gif recording showing the problem…

GridControl

Sub ShowDialog

If Continue Then Exit Sub

DialogLibraries.LoadLibrary("Standard")
oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
oImg = oDlg.getControl("ImageControl1")
Dim oListenerTop As Object
oListenerTop=createUnoListener("TopListen_", "com.sun.star.awt.XTopWindowListener")
oDlg.addTopWindowlistener(oListenerTop)
CenterDialog
Initialize
ExportChartToImage
Update ' **Add this and try again**
Continue = True
done = False

DoEvents
Do while Continue
    Wait 20
    oDlg.setVisible(true)
    If Not done Then
        done = True
        oGrid.gotoCell(0,1)
    End If
Loop

oDlg.dispose()

End Sub

The tuning is build so that Taulukko1 (Sheet1) includes the data and the chart. Taulukko2 (Sheet2) is empty and it’s active. Taulukko1 (Sheet1) has been hidden as whole and Taulukko2 (Sheet2) all columns has been hidden.

Placing the Update line in the ShowDialog routine didn’t help. When you change the value for the first time, simply press Enter twice. That’s enough to update the chart.

Here InteractveGridWithChartToImage.ods
works as described:

  1. 2-click;
  2. set cell value;
  3. Enter.

PWCh

To fix the issue with change of the cell value and updating the chart, when the Dialog box has been loaded

Sub editBoxKeyDown(oEvent)

    If oEvent.KeyCode = com.sun.star.awt.Key.RETURN Then
        Dim editedText As String    
        editedText = editBox.Model.Text
        oSheet.getCellByPosition(xcolumn, xrow + 1).Value = Val(editedText)
        ThisComponent.calculateAll() 'Add these
        Wait 50 ' two lines
        Update
    Else
        Select Case oEvent.KeyCode
            Case 256 To 265        
            Case Else    
                If Len(editBox.Model.Text) < 2  Then
                    editBox.Model.Text = ""
                Else 
                    editBox.Model.Text = Left(editBox.Model.Text, Len(editBox.Model.Text) - 1)
                    oView = editBox.getView()
                    oSelection = New com.sun.star.awt.Selection
                    textLen = Len(editBox.Model.Text)
                    oSelection.Min = textLen
                    oSelection.Max = textLen
                    oView.setSelection(oSelection)
                    oSelection = Nothing
                    oView = Nothing
                End If
        End Select
    End If
    
End Sub

Sub Update

    For i = rowcnt - 1 To 0 Step -1	
        oDataModel.removeRow(i)
    Next i
    editBox.Model.PositionX = editBoxOriginalX
    editBox.Model.PositionY = editBoxOriginalY	
    ReInit = True
    Initialize
    ExportChartToImage
    ThisComponent.store() ' Add this line
    SetFocusOnGrid
	
End Sub