Using graph methods

You call the data-access methods after a graph has been created and populated with data. Some graphs, such as graphs that display data for a page or group of data, are destroyed and re-created internally as the user pages through the data. Any changes you made to the display of a graph, such as changing the color of a series, are lost when the graph is re-created.

Event for graph creation

To be assured that data-access methods are called whenever a graph has been created and populated with data, you can call the methods in the code for an event that is triggered when a graph is created. The event is:

The graph-creation event is triggered by the DataWindow control after it has created a graph and populated it with data, but before it has displayed the graph. By accessing the data in the graph in this event, you are assured that you are accessing the current data and that the data displays the way you want it.

Setting up the PowerBuilder user event

PowerBuilder provides an event ID, pbm_dwngraphcreate, that you can assign to a user event for a DataWindow control.

StepsTo access data properties of a graph in a DataWindow control:

  1. Place the DataWindow control in a window or user object and associate it with the DataWindow object containing the graph.

    Next you create a user event for the DataWindow control that is triggered whenever a graph in the control is created or changed.

  2. Select Insert>Event from the menu bar.

    The Script view displays and includes prototype fields for adding a new event.

  3. Select the DataWindow control in the first drop-down list of the prototype window.

    If the second drop-down list also changes to display an existing DataWindow event prototype, scroll to the top of the list to select New Event or select Insert>Event once again from the menu bar.

    The sample screen shows the Script view with prototype fields for adding a new event. The DataWindow control d w _ 1 is selected in the first drop-down list at upper left. The second drop-down list, at upper right, displays ( new Event ). Additional drop down lists are access, which is grayed out, return type, with a default of none, Event Name, Pass By, with a default of value, and Argument Type, with a default of integer. Text input fields follow for Argument Name and throws:. There is a check box for External, and a drop down list for Event I D, with a default of none. At the bottom is an empty text display area for script.
  4. Name the user event you are creating.

    For example, you might call it GraphCreate.

  5. Select pbm_dwngraphcreate for the event ID.

    The sample window is titled Script - d w _ 1 for graph  create returns long. The first drop down list displays d w _ 1. The second displays graph create ( ) returns long (pbm. The Event Name displayed is Graph Create, and the Event ID is p b m _ d w n graph create.
  6. Click OK to save the new user event.

  7. Write a script for the new GraphCreate event that accesses the data in the graph.

    Calling data access methods in the GraphCreate event assures you that the data access happens each time the graph has been created or changed in the DataWindow.

Examples

PowerBuilder The following statement sets to black the foreground (fill) color of the Q1 series in the graph gr_quarter, which is in the DataWindow control dw_report. The statement is in the GraphCreate event, which is associated with the event ID pbm_dwngraphcreate in PowerBuilder:

dw_report.SetSeriesStyle("gr_quarter", "Q1", &
		foreground!, 0)

The following statement changes the foreground (fill) color to red of the second data point in the Stellar series in the graph gr_sale in a window. The statement can be in a script for any event:

int SeriesNum
// Get the number of the series.
SeriesNum = gr_sale.FindSeries("Stellar")

// Change color of second data point to red
gr_sale.SetDataStyle(SeriesNum, 2, foreground!, 255)

Web ActiveX The following statement sets the foreground (fill) color to black in one of the series in the graph gr_quarter, which is in the DataWindow control dw_report. The statement is in the onGraphCreate event:

dw_report.SetSeriesStyleColor("gr_quarter", 1, 0, 0);

For more information

For complete information about the data-access graph methods, see the DataWindow Reference.

For more about PowerBuilder user events, see the PowerBuilder Users Guide.