Amogh Talpallikar
Amogh Talpallikar

Reputation: 12184

How to make a graph with X-Y scale to accommodate a set of 2D points?

I have a graph to be displayed in an iphone in landscape and portrait mode. I have a set of points stored in a collection in terms of portrait mode. I have done calculations to make them appear in the same manner on landscape as well.

My problem is I need to plot numbers on X and Y axis and plot the points according to that of graph and not the screen coordinates I captured.

and more importantly, the scale and numbers on X-Y axis should be generated to accomodate every point in that collection such that nothing goes out of the bounds of the screen/graph.

Size in pixels of the grids remain the same in landscape/portrait.

Only the scale changes. but the change should also be such that points are in multiples of 5,10,100,150 etc. How should I go about it ?

Upvotes: 0

Views: 306

Answers (1)

Padavan
Padavan

Reputation: 1074

It's simple. You need to calculate a scale. First find max and min points value, then calculate pointsDifference = abs(maxPoint - minPoint), then pixelsDifference = your avaliable space for graph in pixels. Then scale = pixelsDifference / pointsDifference; You can take same scale for box axes or different. And after that you can simple accomodate points.

Upvotes: 1

Related Questions