Using point and click

Users can click graphs during execution. The DataWindow control provides a method called ObjectAtPointer that stores information about what was clicked. You can use this method in a number of ways in mouse events. For example, with the ObjectAtPointer information, you can call other graph methods to report to the user the value of the clicked data point. This section shows you how.

Mouse events and graphs

To cause actions when a user clicks a graph, you might:

You should call ObjectAtPointer in the first statement of the event’s code.

Using ObjectAtPointer

ObjectAtPointer works differently in PowerBuilder and the Web ActiveX.

PowerBuilder ObjectAtPointer has this syntax:

DataWindowName.ObjectAtPointer ( "graphName", seriesNumber,
	dataNumber )

ObjectAtPointer does these things:

Web ActiveX ObjectAtPointer is used with two supporting methods to get all the information. ObjectAtPointer has this syntax:

DataWindowName.ObjectAtPointer ( "graphName" )

To get the information, you:

  1. Call ObjectAtPointer, which returns the kind of graph element the user clicked.

    The element type is identified by a number. For example, if the user clicks on a series, ObjectAtPointer returns 1. If the user clicks on a graph’s title, ObjectAtPointer returns 4.

    For a list of values for individual graph elements, see the chapter on constants in the DataWindow Reference.

  2. Call ObjectAtPointerSeries, which returns the number of the series the pointer was over.

  3. Call ObjectAtPointerDataPoint, which returns the number of the data point the pointer was over.

The second two methods must be called after ObjectAtPointer.

Example

Assume there is a graph named gr_sales in the DataWindow control dw_sales. The following code for the control’s MouseDown event displays a message box:

PowerBuilder This code is for the Clicked event:

int SeriesNum, DataNum
double Value
grObjectType ObjectType
string SeriesName, ValueAsString
string GraphName
GraphName = "gr_sale"

// The following method stores the series number
// clicked on in SeriesNum and stores the number
// of the data point clicked on as DataNum.
ObjectType = &
		dw_printer.ObjectAtPointer (GraphName, &
		SeriesNum, DataNum)

IF ObjectType = TypeSeries! THEN
		SeriesName = &
			dw_printer.SeriesName (GraphName, SeriesNum)
		MessageBox("Graph", &
			"You clicked on the series " + SeriesName)

ELSEIF ObjectType = TypeData! THEN
		Value = dw_printer.GetData (GraphName, &
			SeriesNum, DataNum)
		ValueAsString = String(Value)
		MessageBox("Graph", &
			dw_printer.SeriesName (GraphName, &
			SeriesNum) + " value is " + ValueAsString)
END IF

Web ActiveX This code is for the MouseDown event:

number SeriesNum, DataNum, ObjectType, Success, Value;
string SeriesName, GraphName;

GraphName = "gr_sales";

ObjectType =
		dw_sales.GrObjectAtPointer(GraphName);

if (ObjectType == 1) {
		SeriesName =
			dw_sales.GetSeriesName(GraphName, SeriesNum);

		alert("You clicked on the series " + SeriesName);
}
else {
		if (ObjectType == 2) {
			Success = dw_sales.GetDataNumber(GraphName,
				SeriesNum, DataNum, 1);
			if (Success == 1) {
				Value = GetDataNumberVariable( );

				alert(dw_sales.GetSeriesName(GraphName,
					SeriesNum) +		" value is " + Value);	
			}		}
}