Using the Charts Library > Interacting with Charts > Setting an Interactor on a Chart Object
 
Setting an Interactor on a Chart Object
Several interactors can be used at the same time to interact with a given chart object. These interactors are managed by a dedicated object called a chart interactor manager.
The base class used to represent a chart interactor manager is the IlvChartInteractorManager class. Two methods are available to add an interactor to be managed by a chart interactor manager:
void addInteractor(IlvChartInteractor* interactor,
IlvUInt position=IlvLastPositionIndex)
and
void addInteractor(const char* name,
IlvUInt position=IlvLastPositionIndex)
The first method is used to add a nonshared interactor and the second method to add a shared interactor. The position at which the interactor is added can be specified. This allows you to indicate the priority for dispatching events since interactors are considered in the order of their indexes.
The basic steps to set interactors on a given chart object are the following:
1. Create a chart interactor manager to handle the interactors that will be used to interact with the chart object.
2. Add the interactors to be used with the chart to the created chart interactor manager.
3. Attach the chart interactor manager to the chart object.
Example
The stock sample demonstrates the use of interactors. The source code of this sample can be found in the stock.cpp file in the $ILVHOME/samples/charts/interactors/src directory. This section describes only the steps required to set interactors on the chart.
Creating a Chart Interactor Manager to Manage the Interactors
To create a chart interactor manager to manage the interactors, we use the following code:
IlvChartInteractorManager* interMgr = new IlvChartInteractorManager();
Adding Interactors to the Chart Interactor Manager
For this example, we are going to add a zoom interactor, a pan interactor, and a scroll interactor to the chart interactor manager.
1. First, we add the zoom interactor. We are going to create our own instance of the interactor because we want to set a particular number of intermediate steps for the zoom-in/zoom-out operation.
IlvChartZoomInteractor* zinter = new IlvChartZoomInteractor(); // not shared
zinter->setZoomSteps(4);
interMgr->addInteractor(zinter);
2. Next, we add the pan interactor. We are going to use the shared instance because the default settings of this instance correspond to what we want.
interMgr->addInteractor("ChartPan");
3. Finally, we add the scroll interactor. We also use the shared instance.
interMgr->addInteractor("ChartScroll");
Attaching the Chart Interactor Manager to the Chart Object
To attach the chart interactor manager to the chart object, we use the following code:
IlvChartInteractorManager::Set(chart, interMgr);

Version 5.6
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.