Objective Chart : PART II Programmer’s Guide : Chapter 24 Chart Combinations
Chapter 24 Chart Combinations
Sharing the Data Array
While it’s possible to display multiple charts using separate SRGraph objects, using multiple display components in a single SRGraph object has advantages. It allows the displays to share a common background and title. As discussed in “Overlaying Displays”, components in the same SRGraph object can access each other’s parameters. In addition, they access the same data array.
By default, the display component plots all the data available in the data array. Multiple display components all plot the same data. This can be useful for displaying the data using different graph types, but generally we want the displays to plot different variables from the data set.
To specify a subset of the data array to be plotted by a display:
1. Call SRGraphComponent::SetScope().
SetScope(int nMinIndex, int nMaxIndex, int nMinGroup, int nMaxGroup) specifies the rectangular subset of the data array to be plotted by the display. Setting a parameter to –1 indicates that the minimum or maximum available index or group is to be used. The scope must be a rectangular subset, so sharing of the data array may require careful planning and, in some cases, duplication of data objects.
2. Call SRGraphStyle::SetRelIndex(TRUE).
In most cases in which SetScope() is called, SetRelIndex(TRUE) should be called also. For charts that get their axis labels from the annotations of the first group of data objects, the relative index flag indicates that the annotations should come from the first group in the scope and not group 0.
The code below sets up two displays. The first display plots the data in groups 0 and 1. The second display plots group 2.
 
SRGraphDisplay *pD=new SRGraphDisplay;
pD->GetStyle()->SetGraphStyle(CX_GRAPH_XYSCATTERG);
pD->GetStyle()->SetAxisStyle(CX_AXIS_AUTOMATIC);
// use data groups 0 and 1 for this curve
pD->SetScope(-1,-1,0,1);
pD->GetStyle()->SetRelIndex(TRUE);
m_Graph.AddComponent(pD);
 
SRGraphDisplay *pD2=new SRGraphDisplay;
pD2->GetStyle()->SetGraphStyle(CX_GRAPH_LINE);
pD2->GetStyle()->SetAxisStyle(CX_AXIS_AUTOMATIC);
// use data group 2 for this curve
pD2->SetScope(-1,-1,2,2);
pD2->GetStyle()->SetRelIndex(TRUE);
m_Graph.AddComponent(pD2);