Paradox Home

Products for
Paradox DOS and Windows

Paradox Info:

Resources

Ordering

 

Paradox Data Analysis Tips and Techniques

Graph Creation via ObjectPAL

The example below creates a new form, adds two tables to the form's data model, links fields between the tables, adds a graph object, and assigns fields to the graph. The parameters of the sample procedure (CreateFormAndGraph) are:

Parameter Definition
strMasterTbl Name of master table
strDetailTbl Name of detail table
strNewForm Name of new form (to be created)
intLinkFields Number of fields that are linked between master and detail tables
strXField Name of X field in graph
strSeries1 Name of Y field in graph (used in scatter plot)
strSeries2 Name of field for regression line
strYTitle Title of Y axis
method CreateFormAndGraph(strMasterTbl string, strDetailTbl string, 
       strNewForm string, intLinkFields smallint, strXField string, 
       strSeries1 string, strSeries2 string, strYTitle string)
  const
    intTwipInch = 1440 ; 1440 twips per inch
  endconst
  var
    frmNew form
    tcMaster TCursor
    uiGraph uiobject
    x smallint
    strReturn, strMethod string
    arMasterFields, arLinkFields array[] string
  endvar

  frmNew.create() ; Create new form
  frmNew.dmAddTable(strMasterTbl) ; Add tables to data model
  frmNew.dmAddTable(strDetailTbl)

  tcMaster.open(strMasterTbl) ; Get master fields for table links 
    tcMaster.enumFieldNames(arMasterFields)
  tcMaster.close()

  arLinkFields.setsize(intLinkFields)
  for x from 1 to intLinkFields
    arLinkFields[x] = arMasterFields[x]
  endfor

  if frmNew.dmLinkToFields(strMasterTbl, arLinkFields, strDetailTbl, arLinkFields) then
    ; Add graph object
    uiGraph.create(ChartTool, 0.5*intTwipInch, 0.25*intTwipInch,
         5.5*intTwipInch, 3*intTwipInch, frmNew)
    uiGraph.name = "SampleGraph"
    uiGraph.visible = True
    uiGraph.BindType = GraphTabular
    uiGraph.GraphType = GraphXY
    uiGraph.TitleBox.Graph_Title.Text = "Sample Graph" 
    uiGraph.XAxisName = strDetailTbl + "." + strXField ; Specify X field name

    uiGraph.CurrentSeries = 1 ; Specify Y fields
    uiGraph.SeriesName = strDetailTbl + "." + strSeries1 
    uiGraph.Series.Line.LineStyle = NoLine
    uiGraph.Series.Marker.Size = 4

    uiGraph.CurrentSeries = 2 ; Regression line
    uiGraph.SeriesName = strDetailTbl + "." + strSeries2 
    uiGraph.Series.Line.LineStyle = SolidLine
    uiGraph.Series.Marker.Size = 0
    uiGraph.YAxis.Graph_Title.Text = strYTitle ; Specify Y Axis title

    strReturn = chr(13) + chr(10) ; Add a method to handle graph titles when record changes
    strMethod = "method action(var eventInfo ActionEvent)" + strReturn
    strMethod = strMethod + "var strData string endvar" + strReturn
    strMethod = strMethod + "if not eventInfo.isPreFilter() then" + strReturn
    strMethod = strMethod + " if eventinfo.actionclass() = DataAction then" + strReturn
    strMethod = strMethod + " DMGet(\""+strMasterTbl+"\", \"DataField\", strData) then" + strReturn
    strMethod = strMethod + " SampleGraph.XAxis.Graph_Title.Text = strData" + strReturn
    strMethod = strMethod + " DMGet(\"" + strMasterTbl + "\", \""
    strMethod = strMethod + arMasterFields[1] + "\", strData) then" + strReturn
    strMethod = strMethod + " SampleGraph.TitleBox.SubTitle.text = strData" + strReturn
    strMethod = strMethod + " endif" + strReturn
    strMethod = strMethod + "endif" + strReturn
    strMethod = strMethod + "endmethod"
    frmNew.MethodSet("Action", strMethod)
  endif
  frmNew.save(strNewForm)
  frmNew.run()
endmethod

Return to Paper