Using point and click
Users can click graphs during execution. PowerScript provides
a function called ObjectAtPointer that stores information about
what was clicked. You can use this function in a number of ways
in Clicked scripts. For example, you can provide the user with the
ability to point and click on a data value in a graph and see information
about the value in a message box. This section shows you how.
Clicked events and graphs
To cause actions when a user clicks a graph, you write a Clicked
script for the graph control. The control must be enabled. Otherwise,
the Clicked event doesn’t occur.
Using ObjectAtPointer
ObjectAtPointer has the following syntax.
1 |
<i>graphName</i>.<b>ObjectAtPointer</b> ( <i>seriesNumber, dataNumber</i> ) |
You should call ObjectAtPointer in the first statement of
a Clicked script.
When called, ObjectAtPointer does three things:
- It returns the kind of object
clicked on as 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 complete list of the enumerated values of grObjectType,
open the Browser and click the Enumerated tab. - It stores the number of the series the pointer was
over in the variable seriesNumber
, which is
an argument passed by reference. - It stores the number of the data point in the variable dataNumber
,
also an argument passed by reference.
After you have the series and data point numbers, you can
use other graph functions to get or provide information. For example,
you might want to report to the user the value of the clicked data
point.
Example
Assume there is a graph gr_sale in a window. The
following script for gr_sale’s Clicked event displays
a message box:
- If the user
clicks on a series (that is, if ObjectAtPointer returns TypeSeries!),
the message box shows the name of the series clicked on. The script
uses the function SeriesName 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 TypeData!), the message box lists the name
of the series and the value clicked on. The script uses GetData
to get the data’s value, given the data’s series
and data point number:1int SeriesNum, DataNum<br />double Value<br />grObjectType ObjectType<br />string SeriesName, ValueAsString<br /><br />// The following function stores the series number<br />// clicked on in SeriesNum and stores the number<br />// of the data point clicked on in DataNum.<br />ObjectType = &<br /> gr_sale.<i>ObjectAtPointer</i> (SeriesNum, DataNum)<br /><br />IF ObjectType = TypeSeries! THEN<br /> SeriesName = gr_sale.<i>SeriesName</i> (SeriesNum)<br /> MessageBox("Graph", &<br /> "You clicked on the series " + SeriesName)<br /><br />ELSEIF ObjectType = TypeData! THEN<br /> Value = gr_sale. <i>GetData</i> (SeriesNum, DataNum)<br /> ValueAsString = String(Value)<br /> MessageBox("Graph", &<br /> gr_sale. <i>SeriesName</i> (SeriesNum) + &<br /> " value is " + ValueAsString)<br />END IF