How do I correctly scale my linear graph?

Hi,
I'm creating a simple application for linear graph plotting, just for learning and fun. At the moment it works pretty much as desired except for one thing: if the x and y axis have different scaling, the graph will be incorrect.
A picture should clarify what I mean: [http://i33.tinypic.com/bhzp89.png]
So basically I suppose I need to find a way for my program to adjust the gradient depending on like, distance between the help lines?
This is my little method which returns the y coordinate based on the given x coordinate:
private int calculateY(int x) {
    int y = (int) (getHeight() - (m*x + b*yLineDist));
    y -= getHeight()/2;
    return y;
}Pretty straightforward; the familiar linear equation. I have to do everything "backwards" because the y axis in Java is inverted compared to the standard "mathematical" one, but I guess you can see that. yLineDist would be the distance between two help lines (or what you should call them). There also exists a corresponding xLineDist.
Any ideas? Thanks in advance.

In general, you want to try to keep your model and display elements separate if you can. For your program, the linear equation is the model, and the graph is your display. Both have x and y elements, and I would probably keep them separate for clarity. modelY = m * modelX + b; then for any modelX and modelY, you have a scale to covert those to displayX and displayY. Your particular example seems to be taking in a modelX and returning a displayY which seems a bit confusing to me.
The main reason for doing it like this is so if you ever want to reuse or update old code, you know what your variables represent. Without looking at the code, you wouldn't know which kind of x and y your calculateY method takes and returns.

Similar Messages

  • How to read 2 scales on 1 graph

    Hi guys,
    - I have a graph displaying 2 plots (amplitude and phase) at the same time.
    - The amplitude scale on the left and phase scale on the right.
    - I'm using a graph cursor in SINGLE-PLOT MODE.
    I'm trying to switch between both scales using "Cursor.Yscale" and/or "Plot.YScaleIdx" properties to read the coordinates of the cursor according to each one of the scales.
    While it works fine when the cursor is in FREE mode, I get the same reading before and after switching the scale in single-point mode. That is, Y1amp and Y1phase indicators display the same result.
    The reading is done in a while loop as seen in the attached picture (example for 2 cursors).
    Any idea what am I missing?
    Attachments:
    2 scales reading.png ‏77 KB

    Hi Steve,
    Thanks for the prompt reply.
    Regarding your solution, I think it would give me the Y value of the second plot for the same Theta point. For example, applying solution#1 on the blue cursor in the picture would give me a result of about -115 deg. (the point the vertical line of the cursor crosses the red phase line. This is not what I wanted, I need the "vertical" value of the cursor on both scales (about -38dB on Amp. scale and about +78 deg. on the phase scale.
    Or did I misunderstand?
    Any way, you did give me a new thinking direction that seems to be working:
    a) I read the Amp. scale position of the cursor and calculate the its relative part of the whole scale (for example, if the scale goes from 0 to -100db and the current position is -25dB, then I know the position is a quarter of the whole scale).
    b) Now, I calculate a quarter of the phase scale and get the missing phase position.
    It's a nice workaround.
    Thanks for the idea!

  • How to adjust the scale of a graph using reference points?

    Hi,
    I'm working on some code to display data from a spectrometer.  I've got to the point of producing an energy vs. intensity graph, but I'm having some problems calibrating the x axis (energy).
    The customer wants to be able to insert filters with a cut-off at known energies, and use those points to work out what positions on the graph correspond to what energies.  In programming terms, I need to  let the user click on the graph at two points with known values, and use those points to recalculate the XScale multiplier and offset (I think).
    I've tried a few different things, and attached  by best attempt so far.  It's a simplified example, but I hope it captures enough of the problem to be useful.  I can't help thinking there must be a simpler way to do this.  Any suggestions?
    Solved!
    Go to Solution.
    Attachments:
    Graph Scaling Example.vi ‏24 KB

    What you have done is good. The only thing that I would have a problem whit is there is no visual response on the graph for the user. You can also do this with cursors. Let them slide cursors on to the two points. It is more visual and you can see where you have selected. I am not sure that it will be much easier than what you have done. You could also use a hybrid of the two methods and have the cursor move to the point that you have selected.
    Tim
    Johnson Controls
    Holland Michigan

  • How to reduce the scale size of HTML graphs

    Hi All,
    i created HTML Graphs in apex 4.0. Can any one tell how i decrease scall size of the graph beasue i saw the options there is min 200 scale size. How to reduce below 200 ?
    Looking forward for the valueable response.
    Regards,
    Omzz

    Have less photos? Really the question is a bit vague and there is no way to redice the size of the library. You can move a library to an external disk:
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    3. Hold down the option (or alt) key while launching iPhoto. From the resulting menu select 'Choose Library' and navigate to the new location. From that point on this will be the default location of your library.
    4. Test the library and when you're sure all is well, trash the one on your internal HD to free up space.
    Regards
    TD

  • My ipad mini just updated to IOS 7 and the scales of my wall paper changed.  How do I correct them?

    My ipad mini just updated to IOS 7 and the scales of my wall paper changed.  How do I correct them?

    I am having the same issue with the sound echo on my iPhone 4S. It seems OK when I talk on the phone, but all the alert sounds do it. It did not happen with the first update to ios 7, just after I updated last night to ios 7.0.2. If anyone figures out a solution, I would love to know. The echo is irritating. Thanks!

  • Is there any way to show linear graph in jSwing?

    Hi,
    I have some table with values of linear graph (logarithmic scale):
    ex. array of ( 10, 1
    100, 1.5
    500, 2
    1000, 2.2)
    How can I show this in visual graph using swing, something like it possible in MS Excel?

    Graph it in Excel and take a screen shot, then display the image with Java.
    or
    You're going to have to write the display routines or get 3rd party objects for your project.

  • The print is too small on various web sites that I open. How can I correct this?

    The print is too small on various web sites that I open. This has never happened on older Firefox versions. How can I correct this so every page I open, the print size is consistent and legible? I don't want to change it every time I open a new site.

    Hi Donna,
    Welcome to the HP Community Forum.
    Font Size and the scale (size) at which a document is printed is controlled within the application just before the job is sent to the printer -  this means the size is set from your browser (Firefox, Internet Explorer) or perhaps your Editor (Word).  Generally speaking, most applications use Print Preview -- or a variation of that program under a different name.
    An explanation and the use of Print Preview is avialble in the following document:
    Change Print Size with Print Preview
    Click the Kudos Thumbs-Up to show you appreciate the help.
    I am pleased to provide assistance on behalf of HP. I do not work for HP. 
    Click Accept as Solution when the Answer provides a Fix or Workaround!
    Kind Regards,
    Dragon-Fur

  • Y scale in XY graph

    Quick question :
    how to scale Y-scale in XY Graph (height about 470 pix)
    so that I can see all integer numbers from 1 to say 32.
    See picture. I try to use property node, but it seems that height of this XY
    Graph doesnt allow me to see all numbers.
    cheers,
    jcz
    [Attachment graph_scale.gif, see below]
    [Attachment graph_scale_prop_node.gif, see below]
    Attachments:
    graph_scale.gif ‏4 KB
    graph_scale_prop_node.gif ‏5 KB

    Hi,
    Please see the attached Vi where I have used YScale.MarkerVals[] property node to write 1,2,...,32 values to the Y scale. Notice that the graph height is less than 470 pixels.
    Regards,
    Ankita A.
    Attachments:
    Y_scale.vi ‏17 KB

  • Color map scale for 3d graph

    Hi
    I have a 3d graph with x,y,z having the surface co-ordinates and w matrix having a value at each co-ordinate. I am trying to scale the color map applied. I know the color map values and and color numbers can be called from the property mode, but how to draw the scale so that it inidcates the color of corresponding values on w matrix.
    Thanks
    Ankit

    Duplicate post see this thread
    http://forums.ni.com/ni/board/message?board.id=170​&message.id=230349#M230349
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • How do I re-scale cropped images in Fianal Cut Express 4?

    How do I re-scale cropped images to the correct aspect ratio in the sequence? I am in Final Cut Express 4. The manual says: 'Modify>Scale to sequence' but I do not see this command in the Modify drop-down menu. Does anyone know where this is located or how to to re-scale? Many thanks for any help.

    I'm not quite sure exactly what the problem is and I am no expert.
    However, if the photos are too small you can simply enlarge them to fit  the frame.
    To do this, select the clip in the timeline and open the Motion tab in the Viewer.
    Drag the Scale slider along until the photo enlarges the correct amount. (If the picture does not enlarge, double click the clip)
    If you have lots of photos which need exactly the same enlargement you can copy (Cmd C) the treated picture and then select all the others.
    Go up to the Edit menu and select "Paste Attributes".
    A window will open. Tick the "Basic Motion" box and all the selected pictures will be enlarged.
    They will then need rendering.

  • Scale of a graph

    I want to reduce the scale of a graph on the web template. Pls advice on how to do this.

    Hi,
    BW BW,
    Follow the steps given by Pradibha given above,scroll down and find the Chart item and right Click on it .
    Choose Edit,
    Click "yes" on the pop up.
    In the Step 5 of 6-->under 'Available axes'
    Click on the Value Axis.
    Below u will see 'Axis properties'
    here enter your requirement as 10 instead of 0 , for 'Minimum Value' which is ur requirement.
    Hope this solves your problem.
    Assigning points is a way of telling thanks in SDN..
    regards,
    Man.

  • Provide scal setting for Graphs in 9i Reports

    I have embedded a Graph in Reports 9i.
    Even afte i provided the Scale parameter as
    Minimum = 0.00
    Maximum = 50,0000
    Increament = 10,0000
    The Y-axis scale is diaplayed as 10k, 20k, 30k
    i want to disply the scale as 10000 ,20000, 30000 How it is pssible ?

    Hi,
    in the FQA-Document for Graphs on OTN (http://www.oracle.com/technology/products/reports/htdocs/faq/graph_faq_with_style.html) there's the same question (By default the Y-axis scale in my graph reads as 1K, 2K... Can I modify the scale to read 1000, 2000...? ) with the answer.
    regards
    Rainer

  • Create different y scale dynamicly on graph

    hello all
         I have a problem that, i need create many different y-scale in the graph, one method is right click the scale, select "Duplicate Scale" 
    then a new scale will be ok. however, this is just static method, before the VI running, the total of the y-scale is fix. Is there some dynamic method
    by call property node to create the new y-scale when the VI is running?  for example, if i do not know how many channel data to be acquired, then
    i can not determine the total quantity of the y-scale, so if dynamic is ok, then , it is very perfect.
         Every one suggetion is very  appreciated.

    We needed to do something similar becuase of a customer requirement. From what you said, if you know the maximum number of axis, create the maximum number of scales required by right clicking and duplicating scale. During runtime hide/unhide the scale as shown below.
    Beginner? Try LabVIEW Basics
    Sharing bits of code? Try Snippets or LAVA Code Capture Tool
    Have you tried Quick Drop?, Visit QD Community.

  • TA24326 My HP desktop running Windows Vista 32-bit no longer recognizes my iPhone 4 when I connect it. How do I correct this?

    My HP desktop running Windows Vista 32-bit no longer recognizes my iPhone 4 when I connect it. How do I correct this?

    Device not recognized in iTunes

  • When trying to udate iTunes on my PC, I recieve the error message "The older version of iTunes cannot be removed"  How do I correct this error and not lose all the music I have in iTunes?

    When trying to update my version of iTunes on my PC with Windows 7,  I receive the error message "The older version of iTunes cannot be romoved".  How do I correct this problem without losing all the music that I have in iTunes on my PC?

    (1) Download the Windows Installer CleanUp utility installer file (msicuu2.exe) from the following Major Geeks page (use one of the links under the thingy on the Major Geeks page):
    http://majorgeeks.com/download.php?det=4459
    (2) Doubleclick the msicuu2.exe file and follow the prompts to install the Windows Installer CleanUp utility. (If you're on a Windows Vista or Windows 7 system and you get a Code 800A0046 error message when doubleclicking the msicuu2.exe file, try instead right-clicking on the msicuu2.exe file and selecting "Run as administrator".)
    (3) In your Start menu click All Programs and then click Windows Install Clean Up. The Windows Installer CleanUp utility window appears, listing software that is currently installed on your computer.
    (4) In the list of programs that appears in CleanUp, select any iTunes entries and click "Remove", as per the following screenshot:
    (5) Quit out of CleanUp, restart the PC and try another iTunes install. Does it go through properly this time?

Maybe you are looking for

  • No data in Portal Database tables for Activity Report

    Hi experts, I've developed an Activity Report application in SAP Portal 7.0, which went live but the report shows no data. We are pulling data from 2 portal database tables: WCR_WEBCONTENTSTAT and WCR_USERPAGEUSAGE In non production environment there

  • Anyone with FCP + SnapzProX experience?

    I've recently purchased SnapzProX, a software that allows you to capture quicktime movies of your actions on a MAC desktop. It works pretty well. However, I'm using it primarily for tutorial purposes, to show students how to perform certain actions i

  • How to attach a hyperlink to a jpeg w ps touch

    how to attach a hyperlink to a jpeg with ps touch?

  • [Desktop][Music] Artist page needs to make it easier to find an album when there are many

    If you visit an artist page with a tonne of albums like Antonín Dvořák it is difficult to find a particular album you're looking for. You have the choice between scrolling through heaps of track listings or using grid view. The former is too much to

  • Material Sales Text.

    I have run across something that I can not find an answer to.   I have searched this Forum, OSS Notes, and tried to Google this as well.  To make a long story short, we no longer have a SD Functional/Technical person and I am trying to learn as I go.