Hi, I'm a beginner and i need help drawing a sine and cosine graph on vb if the equation is given by the user. I'm using the chart function and i know I'm close but just not there yet. It would be greatly appreciated if someone would tell me whats wrong and how to fix it, here is my code.
Chart1.Series.Clear()
Chart1.Titles.Add("Graph")
Dim x(1000) As Integer
Dim y(1000) As Integer
Dim s As New Series
s.ChartType = SeriesChartType.Line
If frmEquation.btnchooseXplus.Checked = True Then
P = Val(frmEquation.txtP.Text) * (-1)
ElseIf frmEquation.btnchooseXMinus.Checked = True Then
P = Val(frmEquation.txtP.Text)
End If
If frmEquation.btnchooseAmpPlus.Checked = True Then
A = Val(frmEquation.txtA.Text)
ElseIf frmEquation.btnchooseAmpMinus.Checked = True Then
A = Val(frmEquation.txtA.Text) * (-1)
End If
If frmEquation.btnchoosePlus.Checked = True Then
Q = Val(frmEquation.txtQ.Text)
ElseIf frmEquation.btnchooseMinus.Checked = True Then
Q = Val(frmEquation.txtQ.Text) * (-1)
End If
For i As Double = 1 To 1000
xpnt = i
ypnt = A * (Math.Sin(Val(frmEquation.txtK.Text)) * (i + P)) + Q
s.Points.AddXY(xpnt, ypnt)
Next
Chart1.Series.Add(s)
I have dimmed APQ those are from the equation of the curve. All that happens now is that a straight line shows up. :( please help someone.
Chart1.Series.Clear()
Chart1.Titles.Add("Graph")
Dim x(1000) As Integer
Dim y(1000) As Integer
Dim s As New Series
s.ChartType = SeriesChartType.Line
If frmEquation.btnchooseXplus.Checked = True Then
P = Val(frmEquation.txtP.Text) * (-1)
ElseIf frmEquation.btnchooseXMinus.Checked = True Then
P = Val(frmEquation.txtP.Text)
End If
If frmEquation.btnchooseAmpPlus.Checked = True Then
A = Val(frmEquation.txtA.Text)
ElseIf frmEquation.btnchooseAmpMinus.Checked = True Then
A = Val(frmEquation.txtA.Text) * (-1)
End If
If frmEquation.btnchoosePlus.Checked = True Then
Q = Val(frmEquation.txtQ.Text)
ElseIf frmEquation.btnchooseMinus.Checked = True Then
Q = Val(frmEquation.txtQ.Text) * (-1)
End If
For i As Double = 1 To 1000
xpnt = i
ypnt = A * (Math.Sin(Val(frmEquation.txtK.Text)) * (i + P)) + Q
s.Points.AddXY(xpnt, ypnt)
Next
Chart1.Series.Add(s)
I have dimmed APQ those are from the equation of the curve. All that happens now is that a straight line shows up. :( please help someone.