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 does not occur.

Using ObjectAtPointer

ObjectAtPointer has the following syntax.

graphName.ObjectAtPointer ( seriesNumber, dataNumber )

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 its 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:

    int SeriesNum, DataNum
    double Value
    grObjectType ObjectType
    string SeriesName, ValueAsString
    
    // The following function stores the series number
    // clicked on in SeriesNum and stores the number
    // of the data point clicked on in DataNum.
    ObjectType = &
             gr_sale.ObjectAtPointer (SeriesNum, DataNum)
    
    IF ObjectType = TypeSeries! THEN
             SeriesName = gr_sale.SeriesName (SeriesNum)
             MessageBox("Graph", &
                "You clicked on the series " + SeriesName)
    
    ELSEIF ObjectType = TypeData! THEN
             Value = gr_sale. GetData (SeriesNum, DataNum)
             ValueAsString = String(Value)
             MessageBox("Graph", &
                gr_sale. SeriesName (SeriesNum) + &
                " value is " + ValueAsString)
    END IF