Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char
Can't get negative axes on my char Can't get negative axes on my char
Can't get negative axes on my char
Go Back  Xtreme Visual Basic Talk > > > Can't get negative axes on my char


Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2012, 05:27 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default Can't get negative axes on my char


Hi i am doin a project where I make quadratic graphs from data but I can't the negative axes to be in the middle
I am doing this project on visual basic 2010 express edition and here is my code.
Code:
Public Class Form1
    Structure graph
        Dim XCoordinate As Decimal
        Dim YCoordinate As Decimal
    End Structure
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim Quadratic As New DataTable
        Dim count As Decimal
        Dim a, b, c As Integer
        Dim Point As graph
        a = TextBox1.Text
        b = TextBox2.Text
        c = TextBox3.Text
        Quadratic.Columns.Add("X", GetType(Decimal))
        Quadratic.Columns.Add("Y", GetType(Decimal))
        For count = -10 To 10 Step 0.01
            Point.XCoordinate = count
            Point.YCoordinate = a * count ^ 2 + b * count + c
            Quadratic.Rows.Add(Point.XCoordinate, Point.YCoordinate)
        Next

        With Chart1.ChartAreas(0)
            .AxisX.Minimum = -10
            .AxisX.Maximum = 10
            .AxisY.Minimum = -5
            .AxisY.Maximum = maximumYValue(a, b, c)
            .AxisY.Interval = 1
            .AxisX.Title = "X"
            .AxisY.Title = "Y"
        End With
        With Chart1.Series(0)
            .Points.DataBind(Quadratic.DefaultView, "X", "Y", Nothing)
            .ChartType = DataVisualization.Charting.SeriesChartType.Line
            .BorderWidth = 4

        End With
    End Sub
    Function maximumYValue(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
        Dim root(1) As Integer
        Dim x, y As Decimal
        root(0) = (-b + Math.Sqrt(b ^ 2 - 4 * a * c)) / 2 * a
        root(1) = (-b - Math.Sqrt(b ^ 2 - 4 * a * c)) / 2 * a
        x = (root(0) + root(1)) / 2
        y = a * x ^ 2 + b * x + c + 1
        Return y
    End Function
End Class
THis is a gif image of graph graph.gif
Thankyou In advance and I have uploaded a picture of the graph y=x^2-4
and I am new to this website so I i don't know all the function yet

Last edited by Flyguy; 06-17-2012 at 08:52 AM.
Reply With Quote
  #2  
Old 06-17-2012, 05:29 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default

sorry about my spelling mistake I really do need to read my work
Reply With Quote
  #3  
Old 06-18-2012, 04:04 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Drawing quadratic graphs

Hi Ktech22 and welcome to the forum.

Did you see this thread?

There was also an exchange on a certain Code Project forum page which you might find useful:
Quote:
Okay, well I am making a graphing calculator, and it's the simplest part i can't seem to figure out.
I have a panel that is 416x416, which the graph will be drawn on.
I have variables, xMin, xMax, yMin, yMax, that store the minimum and maximum for the x and y values.
Now, the first step in rendering the graph is to draw the X and Y axises,
and based on the minimum and maximum of the values will determine where the origin for the graph is.
That's what i'm having problem with,
I can't seem to generate code that will, in pixels, give the origin for the graph.
Right now, the calculator only works if -xMin = xMax = -yMin = yMax,
meaning the origin would be in the center of the 416x416 panel, at point (208, 208).
If the xMax was twice as much as the -xMin, then the X axis would be 1/4 off of the panels left side.
I can't seem to code an algorithm, when passed the xMax, xMin, etc., will return the origin of the graph.
It will work with some values, but not all.
Please let me know if i have not explained enough.

Have you tried (math.abs(xMin) + xMax) / 2
That is if xMin is "-200" and xMax is 400 the result is (200 + 400) / 2 = 300
EDIT: Unless you are already using negative values in X, Y then you would use:
((math.abs(xMin) + xMax) / 2) - math.abs(xMin)
or
((200 + 400) / 2) - 200 = 100

A million thanks. I had tried something like that,
but it was so complicated and didn't even work.
Can't believe it was that simple.
Edit: Maybe you also just need something as simple as how to graph below a line,
which could represent the axis between positive and negative (if you label it as such).
I'll attach a graph plotting sample.
Note: It's the x and y offsets that determine where the graphing occurs,
(including the drawing/placement of the x/y axises),
not necessarily the values being plotted.
Attached Images
File Type: jpg graph.JPG (22.7 KB, 3 views)
Attached Files
File Type: zip Graph_below_line.zip (17.4 KB, 9 views)

Last edited by surfR2911; 06-18-2012 at 06:06 PM.
Reply With Quote
  #4  
Old 06-19-2012, 11:47 AM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default

Thanks a lot for finding it
but i can't seem to get it to work
Is there anything else I can
do and i tried opening the file but the solution
won't open up as some files are missing
thankyou very much
and please could you help me thanks once again
Reply With Quote
  #5  
Old 06-19-2012, 03:48 PM
surfR2911 surfR2911 is offline
Contributor
 
Join Date: Oct 2009
Posts: 719
Default Graph program not missing file..manually recreating ionstructions

Quote:
Originally Posted by Ktech22
..won't open up as some files are missing..
I just downloaded the ""Graph_below_line.zip"" attachment from my last post,
unzipped it and double clicked on "Graph.sln".

The solution came up inside VB.Net Express 2010,
I press F5 and the "Go" command button and it ran.
No errors - no missing files.

To recreate the project manually (step-by-step) in whatever
other version of VB.Net you may be running:
1.) Create a new VB.Net Project
2.) Use "Windows Form Application" as the template type
3.) In the Solution Explore pane you should have a "Form1.vb"
(if the Solution Explore window pane isn't showing go to View menu
and select it, or press CTRL + ALT + L keys)
4.) Right click on it and select "View Designer" (or Shift key & F7 key)
5.) From the toolbox drag two command buttons and one picturebox
onto the form.
6.) For first command button control, name it "cbGo", with Text property of "&Go"
(using the Properties Window - if the Properties Window isn't showing use the View menu
to bring it back or press the F4 key)
7.) For second command button control, name it "cbExit", with Text property of "E&xit"
(using the Properties Window)
8.) For Picturebox control, use the Property Window and name it "pb1",
then (also using the Properties Window) set the Size as follows:
Width = 525
Height = 400
Note: If you don't see "Width" and "Height" immediately below the Size property,
then click on the icon to the left of "Size" and these sub properties will drop down (see screenshot attached below).
9.) Enlarge the form ("Form1.vb") as needed and space the controls as in my screenshot above.
10.) Right click on Form1.vb in the Solution Explorer and select "View Code" (or use F7 key)
11. In the code window for Form1.vb that comes up delete any code that is already there
by default and then copy and paste the following code:
Code:
Imports System.Drawing
Public Class Form1
    Protected g As Graphics
    Protected a As GraphClass
    Private Sub cbGo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbGo.Click
        g = pb1.CreateGraphics()
        a = New GraphClass(g)
        a.SetupFrame()
        For i As Short = 0 To 649
            a.PlotPoint(i, (Math.Sin(i / 57.3) * 100) + 100)
        Next
    End Sub

    Private Sub cbExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbExit.Click
        End
    End Sub
End Class
12.) In the Solution Explorer, right click on the project name
("WindowsApplication1" is usually the default),
then select "Add" -> "Class" (using template "Class")
or use the Project menu and select "Add Class".
13.) In the code window for "Class1.vb" that comes up
copy and paste the following code:
Code:
Public Class GraphClass
        Protected Gain As New Single
        Private Intersection As Point = New Point(FrameCoord.HorizontalDisplacement, _
                                          FrameCoord.X_Axis_VertLoc)
        Protected g As Graphics ' picture box graphic
        Protected AxisColor As Color = System.Drawing.ColorTranslator.FromOle(&HFF00)
        Protected AxisPen As Pen
        'The sample Frame Coord numbers below are just for starting out,
        ' so feel free to adjust for positioning and sizing as desired..
        Protected Enum FrameCoord
            X_Axis_VertLoc = 260
            HorizontalDisplacement = 10
            Y_Axis_XEnd = 650
            Y_Axis_Start = 10
            X_Axis_Begin = HorizontalDisplacement
        End Enum

        Public Sub New(ByVal obj As Graphics)
            ' this graphics is derived from a picture box object in the substantiator
            Gain = 1.0
            g = obj
            AxisPen = New Pen(AxisColor, 2)
        End Sub

        Public Sub SetupFrame()
            Dim pY_Begin As New Point(FrameCoord.HorizontalDisplacement, FrameCoord.Y_Axis_Start)
            Dim pY_End As New Point(FrameCoord.HorizontalDisplacement, FrameCoord.X_Axis_VertLoc)
            Dim pX_Begin As Point = Intersection
            Dim pX_End As New Point(FrameCoord.Y_Axis_XEnd, FrameCoord.X_Axis_VertLoc)
            ' Draw line to screen.
            Drawline(AxisPen, pY_Begin, pY_End)
            Drawline(AxisPen, pX_Begin, pX_End)
            For i As Short = FrameCoord.HorizontalDisplacement + 50 To FrameCoord.Y_Axis_XEnd Step 50
                Drawline(Pens.BlanchedAlmond, New Point(i, FrameCoord.X_Axis_VertLoc - 10), _
                 New Point(i, FrameCoord.X_Axis_VertLoc))
            Next
            For i As Short = FrameCoord.X_Axis_VertLoc - 50 To FrameCoord.Y_Axis_Start Step -50
                Drawline(Pens.BlanchedAlmond, New Point(FrameCoord.HorizontalDisplacement, i), _
                 New Point(FrameCoord.HorizontalDisplacement + 10, i))
            Next
        End Sub

        Public Sub PlotPoint(ByVal X As Integer, ByVal Y As Integer, Optional ByVal pn As Pen = Nothing)
            'The number 100 in the line below is just an offset
            'so feel free to adjust fort positioning
            Dim xp As Integer = (-Y + FrameCoord.X_Axis_VertLoc + 100) * Gain
            If pn Is Nothing Then
                g.DrawLine(AxisPen, New Point(X + Intersection.X, xp), _
                 New Point(X + 1 + Intersection.X, xp + 1))
            Else
                g.DrawLine(pn, New Point(X + Intersection.X, xp), _
                 New Point(X + 1 + Intersection.X, xp + 1))
            End If
        End Sub

        Public Sub Drawline(ByVal P As Pen, ByVal StartPoint As Point, ByVal EndPoint As Point)
            If P Is Nothing Then
                g.DrawLine(AxisPen, StartPoint, EndPoint)
            Else
                g.DrawLine(P, StartPoint, EndPoint)
            End If
        End Sub
    End Class
14.) If you have followed all the instructions correctly
at this point you should be able to press F5 (start debugging) and the
program should run without errors producing the screenshot I attached above to my previous post.
Attached Images
File Type: jpg Screenshot-Using_the_property_window_to_set_size_for_picturebox_control_pb1.JPG (146.3 KB, 2 views)
Attached Files
File Type: zip Form1.zip (2.9 KB, 0 views)
File Type: zip Class_dot_vb.zip (974 Bytes, 1 views)

Last edited by surfR2911; 06-19-2012 at 04:48 PM.
Reply With Quote
  #6  
Old 06-21-2012, 02:25 PM
Ktech22 Ktech22 is offline
Newcomer
 
Join Date: Jun 2012
Posts: 20
Default

Thankyou surfR2911
thank you so so much
I have been trying to solve this problems for 3 weeks
I wish I just joined the forum 3 weeks ago
and got an answer from experts like yourself
THanks once again
KTech22
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char Can't get negative axes on my char
Can't get negative axes on my char
Can't get negative axes on my char
 
Can't get negative axes on my char
Can't get negative axes on my char
 
-->