Results 1 to 16 of 16
Like Tree4Likes
  • 1 Post By Norm
  • 1 Post By Norm
  • 1 Post By Norm
  • 1 Post By Norm

Thread: scaling of negative values in graph

  1. #1
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Exclamation scaling of negative values in graph

    hi,

    my project submission date is tomorrow, so please reply as soon as possible (thanks for reading this line)

    I've drawn the graph, and I've given a scroll-bar for x-axis values.
    this is because, I know how many x-values are there, so I've set the graph resolution to the number of x-values.
    now my y-value need to be scaled
    my y-value maximum value is 0.05299999999917244 and minimum value is -2.147483647E9 (obtained using print statement inside my coding)
    How do I scale them?
    (without scaling, my graph doesn't show accurate all the time)
    I tried this scaling:
    Java Code:
    private double getMax() 
                {
    	       double max = -Integer.MAX_VALUE;
    	       
    	        for(int i = 0; i < this.yArray.length; i++) {
    	            if(this.fftofyArray[i] > max)
    	                max = this.fftofyArray[i];
    	        }
    	        return (max);
    	    }
    //returns the maximum of the y-values

    Java Code:
    final int PAD=30;
    int h = getHeight();
    double scale = (double)(h - 2*PAD)/getMax();
    //scales the positive values according to the height of the graph

    Java Code:
    for(int i = 1; i < this.yArray.length-1; i++) {
    double x1 = PAD + i;
                double y1 =  h - PAD - scale*((this.fftofyArray[i]));
                
                double x2 = PAD + (i+1);
                double y2 =  h - PAD - scale*((this.fftofyArray[i+1]));
                
                g2.draw(new Line2D.Double(x1, y1, x2, y2));
                
            }
    //draw graph with lines y-values.

    x-values are working fine, but y-values negative values are hidden in the graph

    Could you suggest me a different scaling for showing negative values

    Edited to add: fftofyArray[] consists of the y-values
    regards
    dhilip
    Last edited by noobplus; 04-03-2012 at 05:30 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    How do I scale them?
    Use a piece of paper and write down the range of the data values and the range of the graphing numbers.
    Then use division and addition to map from one range into the other.
    lowest in one to 0 in the other, max in one to max in the other.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    Use a piece of paper and write down the range of the data values and the range of the graphing numbers.
    Then use division and addition to map from one range into the other.
    lowest in one to 0 in the other, max in one to max in the other.
    thanks, and is it possible to add a tooltip to the graph, so it makes easy for me..
    I'm using paintComponent() of JPanel to draw the graph. Could we add a tooltip to each point on the graph?
    edited to add: I mean, I've 63,375 values, so difficult to plot on paper , that's what, thanks
    regards
    dhilip
    Last edited by noobplus; 04-03-2012 at 06:16 PM.

  4. #4
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    hi,
    but I know my maximum and minimum values . maximum value is 0.05299999999917244 and minimum value is -2.147483647E9. I got it by using getMax() and getMin() methods.

    regards
    dhilip

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    What have you tried to do with the JToolTip class?
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    What have you tried to do with the JToolTip class?
    the tooltip displays the y-value of the corresponding point, So I can try to scale them.
    not sure,whether JToolTip can be used in JPanel

    regards
    dhilip

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    Have you tried it?
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    Have you tried it?
    yep, I tried..
    Java Code:
    for(int i = 1; i < this.yArray.length-1; i++) {
                double x1 = PAD + i/**xInc*/;
                double y1 =  PAD + 500*((this.fftofyArray[i]));
                
                double x2 = PAD + (i+1)/**xInc*/;
                double y2 =  PAD + 500*((this.fftofyArray[i+1]));
                
                g2.draw(new Line2D.Double(x1, 9*y1, x2, 9*y2));
                setToolTipText(Double.toString(this.fftofyArray[i]));
            }ToolTipManager.sharedInstance().registerComponent( this);
            ToolTipManager.sharedInstance().setInitialDelay(0) ;
    this is the line-drawing loop of my paintComponent()
    but the tooltip i got in output is only the final y-value as a tooltip everywhere

    I need some way to know, which point on the graph has what value

    regards
    dhilip

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    The call to a method in a loop will continually replace the last value with the current value. At the end of the loop only the last value will be there. The other, earlier values will all have been replaced.

    Does the tooltip class have a way to get the mouse click location and set the text based on that?
    noobplus likes this.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    The call to a method in a loop will continually replace the last value with the current value. At the end of the loop only the last value will be there. The other, earlier values will all have been replaced.

    Does the tooltip class have a way to get the mouse click location and set the text based on that?
    nop, all I have is that line-drawing loop, and don't know to get the mouse click location(the location should be on the line drawn which is done by my line-drawing-loop).

    regards
    dhilip

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    Then you may have to use a mouse listener and draw your own label at the mouse click location.
    noobplus likes this.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    Then you may have to use a mouse listener and draw your own label at the mouse click location.
    but Is there a way to scale the graph using the maximum and minimum values of my y-axis-array?
    I got the maximum and minimum values of my y-axis-array using "getMax()" and getMin() and they are maximum is 0.05299999999917244 and minimum is -2.147483647E9

    regards
    dhilip

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    a way to scale the graph
    Use arithmetic operations like - / * and +
    noobplus likes this.
    If you don't understand my response, don't ignore it, ask a question.

  14. #14
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    Use arithmetic operations like - / * and +
    hi,
    i've calculated the maximum value of positive values, and minimum of negative value, and added the modulus of two values, and got a new max-value..
    Java Code:
    private double getMax() {
    	       double max = -Integer.MAX_VALUE;
    	       
    	        for(int i = 0; i < this.yArray.length; i++) {
    	            if(this.fftofyArray[i] > max)
    	                max = this.fftofyArray[i];
    	        }
    	        double min=Integer.MAX_VALUE;
    	        for(int i = 0; i < this.yArray.length; i++) {
    	            if(this.fftofyArray[i] < min)
    	                min = this.fftofyArray[i];
    	            
    	        }
    	        
    	        
    	        return (max-min);
    	    }
    now i've divided the graph height by the answer of getMax()
    Java Code:
    double scale = (double)(h - 2*PAD)/getMax();//int h = getHeight();//h is the height of the graph, and PAD is initialized to 20 for bordering
    now I've plotted y as
    Java Code:
    double y1 =  h-PAD - scale*((this.fftofyArray[i]));
    Java Code:
    double y2 =  h-PAD - scale*((this.fftofyArray[i+1]));
    and then I drew the line,
    I don't get negative values yet on the graph, Could you tell me what's wrong with my scaling

    regards
    dhilip

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,556
    Rep Power
    25

    Default Re: scaling of negative values in graph

    An example:
    data range: -1000 to 1000 (2000 items)
    graph range: 0 to 99 (100 items)
    Plot -1000 at 0 (-1000 - (-1000) = 0)
    plot 1000 at 99
    plot 0 at 50
    noobplus likes this.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    noobplus's Avatar
    noobplus is offline Senior Member
    Join Date
    Feb 2012
    Location
    chennai,south of India(south east of asia)
    Posts
    232
    Rep Power
    3

    Default Re: scaling of negative values in graph

    Quote Originally Posted by Norm View Post
    An example:
    data range: -1000 to 1000 (2000 items)
    graph range: 0 to 99 (100 items)
    Plot -1000 at 0 (-1000 - (-1000) = 0)
    plot 1000 at 99
    plot 0 at 50
    Hi,
    sorry there was power cut that day, there was no power for past four days.. thank you very much, the scaling worked

    regards
    dhilip

Similar Threads

  1. Double with no negative values.
    By vahini in forum New To Java
    Replies: 11
    Last Post: 05-05-2011, 09:07 AM
  2. Replies: 0
    Last Post: 01-23-2011, 09:14 PM
  3. Negative one for illegal/default values
    By diablo84 in forum New To Java
    Replies: 1
    Last Post: 08-08-2010, 07:58 PM
  4. scaling image
    By OmerHalit in forum Advanced Java
    Replies: 3
    Last Post: 05-07-2010, 01:30 AM
  5. scaling images
    By willemjav in forum Java Applets
    Replies: 7
    Last Post: 06-19-2008, 09:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •