jQuery in Action, 2nd edition*
The moose likes Swing / AWT / SWT and the fly likes regarding draw a graph with zoom speciality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "regarding draw a graph with zoom speciality" Watch "regarding draw a graph with zoom speciality" New topic
Author

regarding draw a graph with zoom speciality

karthik tvn
Greenhorn

Joined: Feb 15, 2008
Posts: 13
Hi to all,

i have a text file which contains the x,y coordinates of the sinewave.Using these coordinates i need to draw the sinewave graph.Then,i need an option in graph to zoom in and zoom out the graph.How should i do this? kindly post any ideas,if any open source is available please provide me link.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Welcome to JavaRanch.

The Code Barn contains sample code to draw both X/Y graph and a sine curve.

What ideas have you had for implementing the zoom?


Ping & DNS - my free Android networking tools app
karthik tvn
Greenhorn

Joined: Feb 15, 2008
Posts: 13
thanks for your information. i did draw a xy graph.But i want the coordinates are should be taken from file called as sinewave.txt file.

i dont know about zoom operation.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Do you know how to use the java.io package to read data from a file?

As for zooming, let's say the image is centered on point (x0, y0), has a width of w and a height of h (in terms of the data displayed, not screen coordinates). Zooming in would mean that w and h get smaller by some factor f.

So instead of drawing x coordinates from x0-w/2 to x0+w/2 and y coordinates from y0-h2/ to y0+h/2, you would draw from x0-w/(2*f) to x0+w/(2*f) and y coordinates from y0-h/(2*f) to y0+h/(2*f). f might be in the order of 1.5 (or maybe sqrt(2) ) for each zoom step. Does this help?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Would the scale method of Graphics2D be of any use, do you think, Ulf?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Would the scale method of Graphics2D be of any use

Not without preceding and subsequent translate method calls, in which case we're into using affine transformations (which may or may not be something the OP is familiar with).
[ February 17, 2008: Message edited by: Ulf Dittmer ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
Originally posted by Ulf Dittmer:

Not without preceding and subsequent translate method calls, in which case we're into using affine transformations (which may or may not be something the OP is familiar with).
Agree. AffineTransforms count as bravery beyond the call of duty.
 
jQuery in Action, 2nd edition
 
subject: regarding draw a graph with zoom speciality
 
Similar Threads
tooltip
big O notation
how to draw lines across components
Zooming Graph
How do I store a graph into a picture file?