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;
// use data groups 0 and 1 for this curve
SRGraphDisplay *pD2=new SRGraphDisplay;
// use data group 2 for this curve