Back to Devexpress

TdxCustomChartControl.LoadFromStream(TStream) Method

vcl-dxchartcontrol-dot-tdxcustomchartcontrol-dot-loadfromstream-x28-system-dot-classes-dot-tstream-x29.md

latest6.0 KB
Original Source

TdxCustomChartControl.LoadFromStream(TStream) Method

Loads series data from the specified stream populated by a SaveToStream procedure call.

Declaration

delphi
procedure LoadFromStream(AStream: TStream);

Parameters

NameTypeDescription
AStreamTStream

The source stream with series data.

|

Remarks

Call the LoadFromStream procedure to load all series data from all diagrams that the Chart control has at the moment of the SaveToStream procedure call that created the specified source data stream.

Important

The SaveToStream procedure saves only series data, and the resulting stream does not include information about the Chart control layout, diagrams, and their series. You need to store this information separately.

Code Example: Populate Unbound Bar Series from a Stream

The following code example creates an XY diagram with two Bar chart series, configures diagram and axis titles, and loads data previously saved by a SaveToStream procedure call:

delphi
uses cxDataStorage; // Declares the TcxStringValueType class
// ...
var
  AFileStream: TFileStream;
  AXYDiagram: TdxChartXYDiagram;
  AXYSeries: TdxChartXYSeries;
  ADataBinding: TdxChartXYSeriesUnboundDataBinding;
begin
  dxChartControl1.BeginUpdate; // Initiates the following batch change
  try
    AFileStream := TFileStream.Create('DevAVSales.dat', fmOpenRead);
    try
      AXYDiagram := dxChartControl1.AddDiagram<TdxChartXYDiagram>('DevAV Sales by Region');
      AXYDiagram.Title.Appearance.FontOptions.Size := 20;
      AXYDiagram.Axes.AxisY.Title.Text := 'Millions of Dollars';
      AXYSeries := AXYDiagram.AddSeries('2018');
      // Selects the unbound data access mode
      AXYSeries.DataBindingClass := TdxChartXYSeriesUnboundDataBinding;
      AXYSeries.ViewClass := TdxChartXYSeriesBarView; // Selects the Bar series View
      ADataBinding := AXYSeries.DataBinding as TdxChartXYSeriesUnboundDataBinding;
      ADataBinding.ArgumentField.ValueTypeClass := TcxStringValueType; // Selects the string data type
      AXYSeries.View.ValueLabels.Visible := True; // Displays value labels on bars
      AXYSeries := AXYDiagram.AddSeries('2019');
      // Selects the unbound data access mode
      AXYSeries.DataBindingClass := TdxChartXYSeriesUnboundDataBinding;
      AXYSeries.ViewClass := TdxChartXYSeriesBarView; // Selects the Bar series View
      ADataBinding := AXYSeries.DataBinding as TdxChartXYSeriesUnboundDataBinding;
      ADataBinding.ArgumentField.ValueTypeClass := TcxStringValueType; // Selects the string data type
      AXYSeries.View.ValueLabels.Visible := True; // Displays value labels on bars
      dxChartControl1.LoadFromStream(AFileStream);
    finally
      AFileStream.Free; // Releases the file stream regardless of the data load operation's success
    end;
  finally
    dxChartControl1.EndUpdate; // Calls EndUpdate regardless of the batch change's success
  end;
end;
cpp
#include "cxDataStorage.hpp" // Declares the TcxStringValueType class
// ...
  TFileStream *AStream;
  TdxChartXYDiagram *AXYDiagram;
  TdxChartXYSeries *AXYSeries;
  TdxChartXYSeriesUnboundDataBinding *ADataBinding;
  // ...
  dxChartControl1->BeginUpdate(); // Initiates the following batch change
  try
  {
    AFileStream = new TFileStream("DevAVSales.dat", fmOpenRead);
    try
    {
      AXYDiagram = new TdxChartXYDiagram(dxChartControl1->Owner);
      AXYDiagram->SetParentComponent(dxChartControl1);
      AXYDiagram->Title-Text = "DevAV Sales by Region";
      AXYDiagram->Title->Appearance->FontOptions->Size = 20;
      AXYDiagram->Axes->AxisY->Title->Text = "Millions of Dollars";
      AXYSeries = AXYDiagram->AddSeries("2018");
      // Selects the unbound data access mode
      AXYSeries->DataBindingClass = __classid(TdxChartXYSeriesUnboundDataBinding);
      AXYSeries->ViewClass = __classid(TdxChartXYSeriesBarView); // Selects the Bar series View
      ADataBinding = dynamic_cast<TdxChartXYSeriesUnboundDataBinding*>(AXYSeries->DataBinding);
      // Selects the string data type for arguments
      ADataBinding->ArgumentField->ValueTypeClass = __classid(TcxStringValueType);
      AXYSeries->View->ValueLabels->Visible = true; // Displays value labels on bars
      AXYSeries = AXYDiagram->AddSeries("2019");
      // Selects the unbound data access mode
      AXYSeries->DataBindingClass = __classid(TdxChartXYSeriesUnboundDataBinding);
      AXYSeries->ViewClass = __classid(TdxChartXYSeriesBarView); // Selects the Bar series View
      ADataBinding = dynamic_cast<TdxChartXYSeriesUnboundDataBinding*>(AXYSeries->DataBinding);
      // Selects the string data type for arguments
      ADataBinding->ArgumentField->ValueTypeClass = __classid(TcxStringValueType);
      AXYSeries->View->ValueLabels->Visible = true; // Displays value labels on bars
      dxChartControl1->LoadFromStream(AFileStream);
    }
    __finally
    {
      delete AFileStream; // Releases the file stream regardless of the data load operation's success
    }
  }
  __finally
  {
    dxChartControl1->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }
  // ...

See Also

TdxCustomChartControl Class

TdxCustomChartControl Members

dxChartControl Unit