2

I’ve been asked to make a chart that displays how many users are on each page. This chart will be color-coded, where the page with the most users will have 100% opacity, the page with the least viewers will have 40% opacity and the pages in between will have a corresponding opacity.

So, I have a set of numbers, I need

  • The largest number to be 100%
  • The smallest number to be 40%
  • The numbers in between to fall between 100% and 40%

The numbers can be any whole number 1 or greater.

So given 1000, 500, 100, 50

  • 1000 should be 100%
  • 500 should be ??
  • 100 should be ??
  • 50 should be 40%

Or, given 2, 1

  • 2 should be 100%
  • 1 should be 40%

Or given 1000, 1

  • 1000 should be 100%
  • 1 should be 40%

Or given 7485, 395, 3

  • 7485 should be 100%
  • 395 should be ??
  • 3 should be 40%

I hope that makes sense.

What equation can I use to solve this?

I know to get the percent is just (# / largest_number) * 100 but I’m lost trying to get it between 100% and 40%

The closest I could get is ((#/largest_number) * 60) + 40, but that assumes 0 is the smallest number and gives me 43 for my smallest number in the 1st set of numbers (50) instead of 40% like I need.

Thanks in advance!

1 Answer 1

2

Instead of getting the percent with (# / largest_number) * 100 do x = ((# - lowest_number) / (largest_number - lowest_number) * 100

This is a basic normalization function - see here for details.

This way largest number will always map to 1 and lowest_number will always map to 0, then you can interpolate using your function (x * 60) + 40

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like I would be best off losing the *100 in your suggestion to keep it between 1 and 0 but this EXACTLY what I was looking for, thank you!
Indeed, you don't need the *100!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.