Standard Data Model
The structure of the SRGraphData and SRGraphDataList classes, which comprise the Standard data model, is described in Chapter 3, “Design Overview of Objective Chart.” Those details do not need to be repeated here.
Instead, this section focuses on listing the features of the Standard model that differentiate it from the other two models. A brief code sample illustrates how the data storage objects are created and assigned values.
Standard Model Features
The Standard data model has these features:
*Data values are stored in special SRGraphData objects.
*Each SRGraphData object has its own style member. Each data item can be given an individual appearance. For example, out-of-range or exceptional data items can be highlighted. Alternatively, the color of wigets can vary to represent an additional variable.
*Each SRGraphData object has its own annotation list. The annotations are used as axis labels for some graph types. Annotations can also be displayed as feedback in chart tips.
*Each SRGraphData object has a null data flag. Missing or invalid measurements can be flagged. The handling of the null flag depends on the chart type. Most graphs ignore data values flagged as null.
*Each SRGraphData object has a CScale member that retains the highest and lowest values that have historically been assigned to the data object. These values are plotted by the Stock and AreaStock graphs. They could be used to store data for error bars or other information for custom graph types.
*In normal use, the data objects are created, maintained, and destroyed by the SRGraph chart object. That is, the SRGraphData objects and SRGraphDataList objects are created automatically whenever a new cell in the data array is accessed. The programmer does not have to explicitly create or destroy them — although he or she may. The data objects seem to be internal to Objective Chart.
*Linked lists make inserting or deleting objects from the middle of the list easy. Because SRGraphDataList is derived from CObList, standard MFC access methods can be used. The use of lists makes data rolling particularly efficient— see Chapter 22, “Data Rolling.”
Using the Standard Model
To initialize a chart using the Standard data storage model:
*Create an SRGraph object somewhere in your application.
*Use the SRGraph.SetValue() and SetText() functions to assign values and annotations to data objects. If the referenced data object does not already exist, it is created automatically.
SRGraph m_Graph;
CString s;
for(int i = 0; i < 10; i++)
for(int g = 0; g < 3; g++)
m_Graph.SetValue(i, g, rand() % 150);
s.Format(_T(" (%d, %d) "), i, g);
m_Graph.SetText(i, g, s);