Description This function creates an instance of a user 2D plot and returns the identification number of that plot.
Procedure for adding the References to Chart3D and Chart2D In the script editor, right mouse click to bring up the context menu and then choose Edit > References. From the references dialog, scroll down in the list and toggle the "ComponentOne Chart 8.0 2D Control (8.0)" and "ComponentOne Chart 8.0 3D Control (8.0)" options. Adding these references allows you dimension variables as type Chart2D and Chart3D and use the syntax tooltip helpers in the script editor to view the object's properties and methods.
If the chart 2D and 3D references cannot be added in the manner described above, it may be necessary to add them manually through the chart control *.ocx files directly. If this is required, the user should make sure that FRED is being run as an Administrator. Right mouse click in the script editor and then choose Edit > References. In the references dialog, choose the Browse button. Navigate to C:\Windows\System32 and filter for ActiveX Controls (*.ocx) files, then choose olch2x8.ocx for the 2D chart control and olch3x8.ocx for the 3D chart control. If running a 32-bit version of FRED, the *.ocx files may be located in the C:\Windows\SysWOW64 directory.
Syntax plotID = AddUser2DPlot( )
Parameters plotID As Long Identification number of the 2D plot. This number is used when retrieving and setting information to the chart.
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
|