I would like it to show 1, 10, 100, etc. on the Y-Axis and have them equally spaced.
Also is it safe to use the .NET Bitmap class with IntPtr and Dispose(), rather than mapping to the Windows API and DeleteObject().
That way I can use Bitmap.FromHBitmap() to create a .NET Bitmap struct.
and set the PictureBox's Image property directly to the Bitmap instead of having to use the ugly Windows API CreateCompatibleDC(), BitBlt(), etc to draw the plot in my form.
I was wondering why the example does not do it the .NET way.
Anyway, here is the command string (for the plot). Please tell me how I would change it to get the log scale working on Y-Axis.
Code: Select all
cmds = "[ManualScale(0,1,10,10000)]"
cmds = cmds & "[Caption(" & Chr(34) & "DPLOTLIB XY Test" & Chr(34) & ")]"
cmds = cmds & "[FontPoints(1,8)][FontPoints(2,12)][FontPoints(3,12)]"
cmds = cmds & "[FontPoints(4,10)][FontPoints(5,10)][FontPoints(6,8)]"
cmds = cmds & "[Legend(1," & Chr(34) & "x^2" & Chr(34) & ")]"
cmds = cmds & "[Legend(2," & Chr(34) & "cos({\sp}x)" & Chr(34) & ")]"
cmds = cmds & "[DocMaximize()][ClearEditFlag()]"
Code: Select all
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim d As DPLOT
Dim i As Integer
Dim N As Integer
Dim x() As Double
Dim y() As Double
Dim PI As Double
Dim cmds As String
Dim ret As Integer
' Plot sin(PI*x) and cos(PI*x) from x = 0 to 4.
' In this case we've used DATA_XYYY (one X array for one or more Y arrays).
'
' Since the X values are evenly spaced we could also use
' DATA_DXY - X has only 2 elements, DX and X0
'
' And you can ALWAYS use
' DATA_XYXY - Each curve uses its own X array. This is the only
' option available if the curves have different X values or
' a different number of points.
PI = 4.0# * System.Math.Atan(1.0#)
N = 1001
ReDim x(N - 1)
ReDim y(2 * N - 1)
For i = 0 To N - 1
x(i) = (4.0# * i) / (N - 1)
y(i) = System.Math.Sin(PI * x(i))
y(i + N) = System.Math.Cos(PI * x(i))
Next i
d.Initialize()
d.Version = DPLOT_DDE_VERSION
d.DataFormat = DATA_XYYY
d.MaxCurves = 2 ' Must be >= number of curves we plot
d.MaxPoints = N ' Anything >= N will do
d.NumCurves = 2
d.ScaleCode = SCALE_LINEARX_LOGY
d.LegendX = 0.05
d.LegendY = 0.05
d.NP(0) = N
d.LineType(0) = LINESTYLE_SOLID
d.LineType(1) = LINESTYLE_LONGDASH
d.Title1 = "Data sent to DPlot via DPLOTLIB.DLL"
d.XAxis = "x"
d.YAxis = "y"
cmds = "[ManualScale(0,10,10,10000)]"
cmds = cmds & "[Caption(" & Chr(34) & "DPLOTLIB XY Test" & Chr(34) & ")]"
cmds = cmds & "[FontPoints(1,8)][FontPoints(2,12)][FontPoints(3,12)]"
cmds = cmds & "[FontPoints(4,10)][FontPoints(5,10)][FontPoints(6,8)]"
cmds = cmds & "[Legend(1," & Chr(34) & "x^2" & Chr(34) & ")]"
cmds = cmds & "[Legend(2," & Chr(34) & "cos({\sp}x)" & Chr(34) & ")]"
cmds = cmds & "[DocMaximize()][ClearEditFlag()]"
ret = GetClientRect(Picture1.Handle.ToInt32, rcPic)
Dim rect As Rectangle = Picture1.ClientRectangle
If (Not (myBmp Is Nothing)) Then
myBmp.Dispose()
myBmp = Nothing
End If
DocNum = DPlot_Plot8(d, x(0), y(0), cmds)
If (DocNum > 0) Then
DPM.size = Len(DPM)
hBitmap2 = DPlot_GetBitmapEx(DocNum, rect.Right - rect.Left, rect.Bottom - rect.Top, DPM)
myBmp = Bitmap.FromHbitmap(hBitmap2)
HasMetrics = 1
Picture1.Image = myBmp
' Be sure to do a FileClose after DPlot_GetBitmapEx (if you're done with the document)
ret = DPlot_Command(DocNum, "[FileClose()]")
End If
End Sub