Navigation: Scripting Reference Manual > Functions & Subroutines > GetObjUser2DPlot

 

GetObjUser2DPlot

 

Contact Us: fredsupport@photonengr.com

 

Description

This function returns the ComponentOne chart object for a user 2D plot.  Once the object is assigned, all methods and variables of the chart control object are accessible and can be modified.  Manipulating the chart object is equivalent to accessing the Advanced options in the GUI for a given chart and will allow the user to customize features such as line color and style, axis fonts, plot colors, etc.  Documentation of the chart object is available in the ComponentOne help file: C:\WINDOWS\Help\olch2d8u.chm.

 

 

Syntax

chartObj = GetObjUser2DPlot( plotID )

 

 

Parameters

chartObj (Object, or Chart2D)

Returned user 2D chart object.  The chartObj variable can be dimensioned either as a generic Object or as a Chart2D object.  When the variable has been dimensioned as a Chart2D object, the methods and variables in the chart object can be conveniently displayed in the built-in syntax helper.  To dimension this variable as a Chart2D type:

64-bit: Right mouse click in the editor and go to Edit > References.  Find "ComponentOne Chart 8.0 2D Control (8.0)" in the available references list and toggle it active.

32-bit: Right mouse click in the editor and go to Edit > References.  Hit the "Browse" button and find the file "olch2x8.ocx" in the Windows\System32 directory.  Choose this file and hit "Open", then hit "OK" on the References dialog.

 

plotID As Long

Identification number for the plot whose 2D chart object is being returned.

 

 

Example

The following example creates a custom 2D plot initially containing three series of gaussian functions with varying parameters.  Two of the data series are removed from the plot and some generic plot information is reported for the remaining series.

 

Sub Main

 

    'USER SETUP

    Dim x_start As Double, x_end As Double

    Dim num_samps As Long

    x_start = -10

    x_end = 10

    num_samps = 51

 

    ' create a linear array of numbers from min to max

    Dim x_vals( ) As Double

    ReDim x_vals( num_samps-1 )

    linspace( x_start, x_end, num_samps, x_vals() )

 

    ' populate some functions to plot

    Dim x_func() As Double

    Dim x_func1() As Double

    Dim x_func2() As Double

    ReDim x_func( num_samps-1 )

    ReDim x_func1( num_samps-1 )

    ReDim x_func2( num_samps-1 )

    Dim cur_x As Long

    For cur_x = 0 To UBound( x_vals, 1 )

        x_func( cur_x )  = gauss( x_vals( cur_x ), 1, 2 )

        x_func1( cur_x ) = gauss( x_vals( cur_x ), 1, 3 )

        x_func2( cur_x ) = gauss( x_vals( cur_x ), 0.7, 5 )

    Next cur_x

 

    ' dump plot data to ow

    Print "X Val" & Chr(9) & "Y Val"

    For cur_x = 0 To UBound( x_vals, 1 )

        Print x_vals( cur_x ) & Chr(9) & x_func( cur_x )

    Next cur_x

 

    ' create a 2D plot instance

    Dim plot_id As Long

    plot_id = AddUser2DPlot()

 

    ' grab plot object

    ' add reference to the ComponentOne library first

    ' dimension the plot object as Chart2D so we can see

    ' the methods and variables

    Dim plot_obj As Chart2D

    Set plot_obj = GetObjUser2DPlot( plot_id )

    plot_obj.ChartArea.Axes.Item(1).DataMin.IsDefault = True

    plot_obj.ChartArea.Axes.Item(1).DataMax.IsDefault = True

    plot_obj.ChartArea.Axes.Item(1).Min.IsDefault = True

    plot_obj.ChartArea.Axes.Item(1).Max.IsDefault = True

 

    ' set generic graph information

    SetUser2DPlotWindowTitle( plot_id, "Window Title" )

    SetUser2DPlotGraphTitle( plot_id, "Graph Title" )

    SetUser2DPlotXaxisTitle( plot_id, "X Axis Title" )

    SetUser2DPlotYaxisTitle( plot_id, "Y Axis Title" )

    SetUser2DPlotInfoText( plot_id, "Info text entry" )

 

    ' add data series to the plot

    Dim plot_series( 2 ) As Long

    plot_series( 0 ) = AddUser2DPlotSeries( plot_id, x_vals(), x_func() )

    SetUser2DPlotPoint( plot_id, plot_series( 0 ), 50, 9, 1 ) 'point modification test

    SetUser2DPlotLegendLabel( plot_id, 1, "A=1, W=2" )

    plot_series( 1 ) = AddUser2DPlotSeries( plot_id, x_vals(), x_func1() )

    SetUser2DPlotLegendLabel( plot_id, 2, "A=1, W=3" )

    plot_series( 2 ) = AddUser2DPlotSeries( plot_id, x_vals(), x_func2() )

    SetUser2DPlotLegendLabel( plot_id, 3, "A=0.7, W=5" )

 

    ' pause

    Wait 3

    Print ""

 

    ' delete all but one series

    Dim ret_val As Long, num_series As Long, cur_series As Long

    num_series = GetUser2DPlotSeriesCount( plot_id )

    For cur_series = num_series-1 To 1 Step -1

        ret_val = DeleteUser2DPlotSeries( plot_id, plot_series( cur_series ) )

        If ret_val = 0 Then

            Print "Series " & plot_series( cur_series ) & " was successfully removed.

        Else

            Print "Series " & plot_series( cur_series ) & " was not removed."

        End If

    Next cur_series

 

    ' report information about the remaining series

    Dim point_count As Long, point(1) As Double

    point_count = GetUser2DPlotPointCount( plot_id, 1 )

    GetUser2DPlotPoint( plot_id, 1, 50, point(0), point(1) )

    Print ""

    Print "Remaining Series Information: "

    Print "There are " & point_count & " points in the remaining series."

    Print "Point 50 has (x,y)=(" & point(0) & "," & point(1) & ")"

 

    ' get information about the current plot

    Print ""

    Print "Plot Window Information: "

    Print "Current window title: "    & Chr(9) & GetUser2DPlotWindowTitle( plot_id )

    Print "Current graph title: "     & Chr(9) & GetUser2DPlotGraphTitle( plot_id )

    Print "Current X axis title: "    & Chr(9) & GetUser2DPlotXaxisTitle( plot_id )

    Print "Current Y axis title: "    & Chr(9) & GetUser2DPlotYaxisTitle( plot_id )

    Print "Current plot info: "       & Chr(9) & GetUser2DPlotInfoText( plot_id )

    Print "Series legend label: "     & Chr(9) & GetUser2DPlotLegendLabel( plot_id, 1 )

    Print "Current plot identifier: " & Chr(9) & FindUser2DPlot( "Graph Title" )

 

End Sub

 

Sub linspace( ByVal d_start As Double, _

              ByVal d_end As Double, _

              ByVal num_samps As Long, _

              ByRef ret_vals() As Double )

 

    Dim cur_ind As Long

    cur_ind = 0

    Dim cur_samp As Double

    For cur_samp = d_start To d_end+0.0001 Step (d_end-d_start)/(num_samps-1)

        ret_vals( cur_ind ) = cur_samp

        cur_ind = cur_ind + 1

    Next cur_samp

 

 

End Sub

 

Function gauss( x_val, amp, width ) As Double

 

    gauss = amp * Exp( -PI*( x_val / width )^2 )

 

End Function

 

 

See Also

Chart Scripting Commands

 

 

 

 

 

Copyright © Photon Engineering, LLC