4822 posts Interactive Design
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Interviewed on an Envato blog
  • Made it to the Authors' Hall of Fame
+8 more
digitalscience says

I’m working on a graph which range is dynamic, ie the Y axis doesn’t start from 0% to 100% but can start from say 20% to 80%, I got it working for the max value being lower than 100% but not for the min value.

Here is the code, need a maths brain to figure this out! Basically it uses the percentage and the height of the vertical bar to determine the y position of the dots.

Accurate with lowered Max value \\

Not accurate with raised Min value \\

Here is the code in a for loop:

this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n]/Max)

point_mc are the dots, yAxis is the vertical line, Data is a percentage val for each dot, Max and Min are the maximum and minimum (percentage val),

Thanks for your help!

1 post
  • Has been part of the Envato Community for over 2 years
  • Has collected 1+ items on Envato Market
  • Sells items exclusively on Envato Market
lachlanwpearce says
this["point_mc"+n]._y = yAxis._y+yAxis._height this["point_mc"+n]._y -= yAxis._height*(Data[n]/Max) - (yAxis._height * 0.20)
767 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
outandouter says
this["point_mc"+n]._y = yAxis._y+yAxis._height;
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min));
4822 posts Interactive Design
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Interviewed on an Envato blog
  • Made it to the Authors' Hall of Fame
+8 more
digitalscience says

this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n]/Max) - (yAxis._height * 0.20)

\\

Almost now the bottom result is closer, but the top results are off… hmmm. I think it’s an entirely different equation.

4822 posts Interactive Design
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Interviewed on an Envato blog
  • Made it to the Authors' Hall of Fame
+8 more
digitalscience says

this["point_mc"+n]._y = yAxis._y+yAxis._height;
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min));
\\

:D

767 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
outandouter says

I and lachlanwpearce both gave partial answers.

Mix them up and you have:

this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min)) - (yAxis._height * 0.20)

... which will most likely work, IMO .

4822 posts Interactive Design
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Interviewed on an Envato blog
  • Made it to the Authors' Hall of Fame
+8 more
digitalscience says

I and lachlanwpearce both gave partial answers.

Mix them up and you have:

this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min)) - (yAxis._height * 0.20)
... which will most likely work, IMO .

\\

That’s getting closer, but still a lil off.. hmmm

767 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
outandouter says
this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n] / Max) - (yAxis._height * (Min / 100) * (100 - Data[n] ) / 100 )

A little dirtier but this SHOULD work. I didn’t realize that all the values inside Data[n] and Min and Max were percentages earlier.

:delicious:?

4822 posts Interactive Design
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Interviewed on an Envato blog
  • Made it to the Authors' Hall of Fame
+8 more
digitalscience says

this["point_mc"+n]._y = yAxis._y+yAxis._height
this["point_mc"+n]._y -= yAxis._height*(Data[n] / Max) - (yAxis._height * (Min / 100) * (100 - Data[n] ) / 100 )

A little dirtier but this SHOULD work. I didn’t realize that all the values inside Data[n] and Min and Max were percentages earlier.

:delicious:?

^^ That’s very close actually but a fraction off both top and bottom ranges…

this["point_mc"+n]._y = yAxis._y+yAxis._height;
this["point_mc"+n]._y -= ((Data[n]-Min)*yAxis._height)/(Max-Min);

\\

This is the solution in the end :) thanks for the help guys!

3788 posts Community Moderator
  • Helps us moderate the forums
  • Contributed a tutorial on Tuts+
  • Located in Netherlands
  • Made it to the Authors' Hall of Fame
+9 more
Joost Moderator says

I believe it’s

this["point_mc"+n]._y = yAxis._y + yAxis._height * (1 - (Data[n] - Min) / (Max - Min));

Took a bit of adjusting to work with a top-left (0, 0) after spending time working with OpenGL :P

EDIT : Ah shoot, just after the bell :( My solution is identical though, albeit formatted slightly different..

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by