Skip to main content
All docs
V25.2
  • TdxDashboard.ExportTo(TdxDashboardExportFormat,TStream,string) Method

    Exports dashboard content to a stream in any supported format. Returns the file name that corresponds to the dashboard layout name and the target export format.

    Declaration

    procedure ExportTo(AFormat: TdxDashboardExportFormat; AStream: TStream; out AFileName: string); overload;

    Parameters

    Name Type Description
    AFormat TdxDashboardExportFormat

    The target export format. Refer to the following section for details: Available Export Formats.

    AStream TStream

    The target stream.

    AFileName string

    Returns a string that consists of the [Name] property value and the file name extension that corresponds to the target export format (AFormat).

    Remarks

    Call the ExportTo procedure to export dashboard content to a stream in any supported format. You can use the ExportTimeout property to set a timeout interval (in milliseconds) for export operations.

    Tip

    The AFileName parameter is useful if you need to save target stream (AStream) content to a file after the export operation as demonstrated in the following code example: Export Dashboard Content to PDF without User Interaction.

    Available Export Formats

    Pass one of the following values as the AFormat parameter to export dashboard content in the corresponding format:

    AFormat Parameter Value Content Format File Name Extension
    TdxDashboardExportFormat.CSV Comma-Separated Values (CSV) csv
    TdxDashboardExportFormat.GIF Graphics Interchange Format (GIF) gif
    TdxDashboardExportFormat.JPG Joint Photographic Experts Group (JPEG) jpg
    TdxDashboardExportFormat.PDF Portable Document Format (PDF) pdf
    TdxDashboardExportFormat.PNG Portable Network Graphics (PNG) png
    TdxDashboardExportFormat.SVG Scalable Vector Graphics (SVG) svg
    TdxDashboardExportFormat.XLS Microsoft Excel® Binary Format (XLS) xls
    TdxDashboardExportFormat.XLSX Office OpenXML Spreadsheet Format (XLSX) xlsx

    Code Example: Export Dashboard Content to PDF without User Interaction

    The following code example configures a memory-based data source (TdxBackendInMemoryJSONConnection), loads an XML dashboard layout, and exports dashboard content to a PDF file without user interaction:

    uses
      dxBackend.ConnectionString.JSON,  // Declares the TdxBackendInMemoryJSONConnection component
      dxDashboard;                      // Declares the TdxDashboard class
    // ...
    
    procedure TMyForm.cxExportButtonClick(Sender: TObject);
    var
      ADashboard: TdxDashboard;
      AJSONDataConnection: TdxBackendInMemoryJSONConnection;
      AMemoryStream: TMemoryStream;
      AFileName, AJSONData: string;
    begin
      // Define a table that consists of three columns ("id", "Region", and "Sales") and five data rows
      AJSONData :=
    
      '[{"id": 1, "Region": "Asia", "Sales": 4.7685},' +          // Row #1
       '{"id": 2, "Region": "Australia", "Sales": 1.9576},' +     // Row #2
       '{"id": 3, "Region": "Europe", "Sales": 3.3579},' +        // Row #3
       '{"id": 4, "Region": "North America", "Sales": 3.7477},' + // Row #4
       '{"id": 5, "Region": "South America", "Sales": 1.8237}]';  // Row #5
    
      AJSONDataConnection := TdxBackendInMemoryJSONConnection.Create(Self);  // Creates a data connection
      try
        AJSONDataConnection.Name := 'JSONData';        // Assigns a name to the created data connection
        AJSONDataConnection.SetJSONValue(AJSONData);   // Assigns the defined JSON data string
        ADashboard := TdxDashboard.Create(Self);       // Creates a TdxDashboard container
        try
          ADashboard.Layout.LoadFromFile('MyDashboardLayout.xml');  // Loads an XML dashboard layout
          ADashboard.Name := 'MyDashboard';                         // Defines a dashboard name
          AMemoryStream := TMemoryStream.Create;                    // Creates a memory stream
          try
            // Export dashboard content to the created memory stream in the PDF format
            ADashboard.ExportTo(TdxDashboardExportFormat.PDF, AMemoryStream, AFileName);
            AMemoryStream.SaveToFile(AFileName);                    // Saves the resulting PDF file
          finally
            AMemoryStream.Free;                                     // Releases the memory stream
          end;
        finally
          ADashboard.Free;                                          // Releases the TdxDashboard container
        end;
      finally
        AJSONDataConnection.Free;                                   // Releases the data connection
      end;
    end;
    
    See Also