Tom Lilletveit
Tom Lilletveit

Reputation: 2002

Scaling a window while keeping ratios the same

I have a resizable window, and a graph which consists of 11 lines of different values ranging from 0 to 1000. What is the math I would use to compute this?

I want to have the data ranging from 0 to 1000 be so that it equals 0-1000 pixels on screen. But if I resize my window to say 640 / 480, the graph will adjust only will be less detailed.

Upvotes: 1

Views: 55

Answers (2)

Germann Arlington
Germann Arlington

Reputation: 3353

You did not specify a programming language.
In HTML you can size anything as %, so you calculate size as % of maximum - i.e. 550 (out of 1000 max) = 55%
If you use % size it will automatically adjust with screen/window size.

If you specify your programming language of choice we may be able to help you more

Upvotes: 0

Alexander Prokofyev
Alexander Prokofyev

Reputation: 34515

This is a simple proportion: if 640 pixels bar represents value of 1000, value of Y will represent 640 * Y / 1000 pixels bar.

Upvotes: 2

Related Questions