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.

    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

    AFormat Parameter Value Content Format Format-Specific Export Format
    TdxDashboardExportFormat.CSV Comma-Separated Values (CSV) ExportToCSV
    TdxDashboardExportFormat.GIF Graphics Interchange Format (GIF) ExportToGIF
    TdxDashboardExportFormat.JPG Joint Photographic Experts Group (JPEG/JPG) ExportToJPG
    TdxDashboardExportFormat.PDF Portable Document Format (PDF) ExportToPDF
    TdxDashboardExportFormat.PNG Portable Network Graphics (PNG) ExportToPNG
    TdxDashboardExportFormat.SVG Scalable Vector Graphics (SVG) ExportToSVG
    TdxDashboardExportFormat.XLS Microsoft Excel® Binary Format (XLS) ExportToXLS
    TdxDashboardExportFormat.XLSX Office OpenXML Spreadsheet Format (XLSX) ExportToXLSX

    Code Examples

    View Example: Generate Dashboards in a Backend/Service Application

    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