# regarding draw a graph with zoom speciality

karthik tvn

Greenhorn

Posts: 13

posted 9 years ago

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.

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

Rancher

Posts: 42970

73

posted 9 years ago

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?

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?

karthik tvn

Greenhorn

Posts: 13

Ulf Dittmer

Rancher

Posts: 42970

73

posted 9 years ago

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?

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

Marshal

Posts: 52516

118

Ulf Dittmer

Rancher

Posts: 42970

73

Campbell Ritchie

Marshal

Posts: 52516

118