Using the Dynamic Model

To initialize a chart using the Dynamic data storage model:

1.  Create an SRGraph or SRDynamicGraph object somewhere in your application.

Create an SRGraphDynamicData object and set its initial size and growth parameters.

Add the prepared SRGraphDynamicData object to the SRGraphDataList object of the selected group.

Once configured, the Dynamic data buffer can be accessed with the same GetValue() and SetValue() functions that are used in the Standard model, except overloaded functions are provided for a variety of data types. In addition, SRGraphDynamicData has functions that can be used for more direct, sequential access.

 

SRGraph m_Graph;

 

SRGraphDynamicData* pD=new SRGraphDynamicData;

// Allocate the memory

pD->SetBufferSize(15000);

// Decide whether to allow the buffer to grow

// or remain cyclic

// pD->SetGrowSize(4096);

pD->SetCyclic(TRUE);

pD->SetNull(FALSE);

pD->GetStyle()->SetObjectStyle(CX_OBJECT_LINE);

SRGraphDataList* pDL=m_Graph.GetGroup(0);

pDL->SetDynamic(); // important

// Add the data object (buffer) to the list

pDL->AddTail(pD);

// You can add more than one but the second, third

// and so-on will never be seen

 

// Assign data values to the buffer

double x;

for(int i=0; i<15000; i++)

{

//standard access

m_Graph.SetValue( i,0, sin(RADIANS(i)) );

or

 

// faster, direct, sequential access

// via SRGraphDynamicData

pD->SetValue( sin(RADIANS(i)) );

}

Changes have been made to SRGraph, SRDynamicGraph, SRGDynamicDataManager, and SRGraphDynamicData to make Dynamic data easier to use. Dynamic data no longer requires explicit setup of the data buffer for each group as described above. SRGDynamicDataManager::NewGroup() will create and initialize an SRGraphDynamicData object with reasonable defaults.

To switch an existing chart from Standard to Dynamic storage models, simply change the chart object from SRGraph to SRDynamicGraph— or create an SRGDynamicDataManager and select it into the SRGraph using SRGraph::SetDataManager(). Then, in most cases, the data can be initialized using the same code as the Standard data model.

Using SetDataManager() to select an SRGDynamicDataManager is the preferred method because it allows the use of a custom SRGDynamicDataManager. Developers will commonly override SRGDynamicDataManager::NewGroup() to customize the initialization of the SRGraphDynamicData-based object. For example, SRGraphDynamicData::GetAnnotation() is commonly overridden to supply strings (for axis labels, etc.) based on the current index.

Also, SRGraphDynamicData no longer assumes that the entire data buffer is filled with data. It maintains a “high water mark”, m_nMaxValid, indicating the highest index (+1) which has been initialized with a call to SetValue(). m_nMaxValid— accessed by GetHighestValidIndex()— determines the number of data values in the group. GetNull() returns TRUE for uninitialized indices greater than or equal to m_nMaxValid. With these changes, the chart can be dynamically displayed as data are acquired filling up the data buffer.