1.1.4 Creating Graph Preview GetN Dialog

This section shows how to create an X-Function graph preview GetN dialog , including how to initialize a preview graph, how to update the preview graph on a GUI change, and how to update the GUI on the rectangle moving on the graph.

Ocguide xf graphpreview dialog.png

Contents

Create an Empty GetN Graph Preview Dialog

Coding X-Function in Code Builder

Initialize Preview Graph

The GetNGraphPreview_OnInitGraph function is used to initialize a preview graph. Copy the following codes and paste them into the function, then click the Compile button. When the preview dialog box opens, a rectangle will display on the preview graph. Click Compile and run "PrevBox -d" in the Command window.

// cast pgTemp from PageBase class object to GraphPage object
GraphPage gp(pgTemp); 

// load this template to the graph in order to contain zoom 
// in/out button on the graph. If this is not required, 
// remove this line.
page_load(gp, "CurvePreview"); 

// get active graph layer in the graph page
GraphLayer gl = gp.Layers(); 

// add a rectangle, set x position reference to xfrom and xto 
// variables
GraphObject go;
add_rect(gl, go, trGetN.xfrom.dVal, 0, trGetN.xto.dVal, -1, 
    SYSCOLOR_BLUE, 2, LN_VERTICAL, true, false);

Update Preview Graph on GUI Change

Update GUI on Graph Object Event

If you want to update the GUI when you move/resize the rectangle on the preview graph, you need to:

Add Preview buttons

To add a Preview button and an Auto Preview check box, please see X-Functions: Customizing an X-Function: Adding Custom Button on Dialog: Show Preview Button on Graph Preview GetN Dialog