Using graphs

In PowerBuilder, there are two ways to display graphs:

  • In a DataWindow, using data retrieved from the DataWindow data source

  • In a graph control in a window or user object, using data supplied by your application code

This chapter discusses the graph control and describes how your application code can supply data for the graph and manipulate its appearance.

For information about graphs in DataWindows, see DataWindow Programmers Guide and DataWindow Reference.

To learn about designing graphs and setting graph properties in the painters, see Working with Graphs in Users Guide.

Working with graph controls in code

Graph controls in a window can be enabled or disabled, visible or invisible, and can be used in drag and drop. You can also write code that uses events of graph controls and additional graph functions.

Properties of graph controls

You can access (and optionally modify) a graph by addressing its properties in code at runtime. There are two kinds of graph properties:

  • Properties of the graph definition itself

    These properties are initially set in the painter when you create a graph. They include a graph's type, title, axis labels, whether axes have major divisions, and so on. For 3D graphs, this includes the Render 3D property that uses transparency rather than overlays to enhance a graph's appearance and give it a more sophisticated look.

  • Properties of the data

    These properties are relevant only at runtime, when data has been loaded into the graph. They include the number of series in a graph (series are created at runtime), colors of bars or columns for a series, whether the series is an overlay, text that identifies the categories (categories are created at runtime), and so on.

Events of graph controls

Graph controls have the events listed in the following table.

Clicked

DragLeave

Constructor

DragWithin

Destructor

GetFocus

DoubleClicked

LoseFocus

DragDrop

Other

DragEnter

RButtonDown


So, for example, you can write a script that is invoked when a user clicks a graph or drags an object on a graph (as long as the graph is enabled).

Functions for graph controls

You use the PowerScript graph functions in the following table to manipulate data in a graph.

Function

Action

AddCategory

Adds a category

AddData

Adds a data point

AddSeries

Adds a series

DeleteCategory

Deletes a category

DeleteData

Deletes a data point

DeleteSeries

Deletes a series

ImportClipboard

Copies data from the clipboard to a graph

ImportFile

Copies the data in a text file to a graph

ImportString

Copies the contents of a string to a graph

InsertCategory

Inserts a category before another category

InsertData

Inserts a data point before another data point in a series

InsertSeries

Inserts a series before another series

ModifyData

Changes the value of a data point

Reset

Resets the graph's data