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:
- PowerBuilder Write a Clicked script for the DataWindow control
- Web ActiveX Write code for the MouseDown or onButtonClick event
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:
1 |
<i>DataWindowName</i>.<b>ObjectAtPointer</b> ( "<i>graphName</i>", <i>seriesNumber,<br /> dataNumber</i> ) |
ObjectAtPointer does these things:
- Returns the kind of object the user clicked
The object is identified by a grObjectType enumerated value.
For example, if the user clicks on a data point, ObjectAtPointer
returns TypeData!. If the user clicks on the graph’s title,
ObjectAtPointer returns TypeTitle!.For a list of object values, see the chapter on constants
in the DataWindow Reference
. In PowerBuilder,
you can also open the Browser and click the Enumerated tab. - Stores the number of the series the pointer was
over in the variable seriesNumber
, which is
an argument passed by reference - Stores the number of the data point in the variable dataNumber
,
also an argument passed by reference
Web ActiveX ObjectAtPointer is used with two supporting methods to get
all the information. ObjectAtPointer has this syntax:
1 |
<i>DataWindowName</i>.<b>ObjectAtPointer</b> ( "<i>graphName</i>" ) |
To get the information, you:
- 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
. - Call ObjectAtPointerSeries, which returns the number
of the series the pointer was over. - 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:
- If the user clicks on a series
(that
is, if ObjectAtPointer returns 1), the message box shows the name
of the series clicked on. The example uses the method GetSeriesName
to get the series name, given the series number stored by ObjectAtPointer. - If the user clicks on a data point
(that
is, if ObjectAtPointer returns 2), the message box lists the name
of the series and the value clicked on. The example uses GetDataNumber
to get the data’s value, given the data’s series
and data point number.
PowerBuilder This code is for the Clicked event:
1 |
int SeriesNum, DataNum |
1 |
double Value |
1 |
grObjectType ObjectType |
1 |
string SeriesName, ValueAsString |
1 |
string GraphName |
1 |
GraphName = "gr_sale" |
1 |
1 |
// The following method stores the series number |
1 |
// clicked on in SeriesNum and stores the number |
1 |
// of the data point clicked on as DataNum. |
1 |
ObjectType = & |
1 2 |
dw_printer.<i>ObjectAtPointer</i> (GraphName, & |
1 |
SeriesNum, DataNum) |
1 |
1 |
IF ObjectType = TypeSeries! THEN |
1 |
SeriesName = & |
1 2 |
dw_printer.<i>SeriesName</i> (GraphName, SeriesNum) |
1 |
MessageBox("Graph", & |
1 |
"You clicked on the series " + SeriesName)<br /> |
1 |
ELSEIF ObjectType = TypeData! THEN |
1 2 |
Value = dw_printer.<i>GetData</i> (GraphName, & |
1 |
SeriesNum, DataNum) |
1 |
ValueAsString = String(Value) |
1 |
MessageBox("Graph", & |
1 2 |
dw_printer.<i>SeriesName</i> (GraphName, & |
1 |
SeriesNum) + " value is " + ValueAsString) |
1 |
END IF |
Web ActiveX This code is for the MouseDown event:
1 |
number SeriesNum, DataNum, ObjectType, Success, Value; |
1 |
string SeriesName, GraphName; |
1 |
1 |
GraphName = "gr_sales"; |
1 |
1 |
ObjectType = |
1 2 |
dw_sales.<i>GrObjectAtPointer</i> (GraphName); |
1 |
1 |
if (ObjectType == 1) { |
1 |
SeriesName = |
1 2 |
dw_sales.<i>GetSeriesName</i> (GraphName, SeriesNum); |
1 |
1 |
alert("You clicked on the series " + SeriesName); |
1 |
} |
1 |
else { |
1 |
if (ObjectType == 2) { |
1 2 |
Success = dw_sales.<i>GetDataNumber</i> (GraphName, |
1 |
SeriesNum, DataNum, 1); |
1 |
if (Success == 1) { |
1 2 |
Value = <i>GetDataNumberVariable</i> ( ); |
1 |
1 2 |
alert(dw_sales.<i>GetSeriesName</i> (GraphName, |
1 |
SeriesNum) + " value is " + Value); |
1 |
} } |
1 |
} |