5306 posts Interactive Design
  • Elite Author
  • Author Level 10
  • Trendsetter
  • Top Monthly Author
+11 more
meta4creations
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
  • 3 Years of Membership
  • Australia
  • Collector Level 2
  • Exclusive Author
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
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 more
outandouter
says
this["point_mc"+n]._y = yAxis._y+yAxis._height;
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min));
5306 posts Interactive Design
  • Elite Author
  • Author Level 10
  • Trendsetter
  • Top Monthly Author
+11 more
meta4creations
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.

5306 posts Interactive Design
  • Elite Author
  • Author Level 10
  • Trendsetter
  • Top Monthly Author
+11 more
meta4creations
says

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

:D

767 posts
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 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 .

5306 posts Interactive Design
  • Elite Author
  • Author Level 10
  • Trendsetter
  • Top Monthly Author
+11 more
meta4creations
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
  • 6 Years of Membership
  • Author Level 3
  • Collector Level 4
  • Exclusive Author
+4 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:?

5306 posts Interactive Design
  • Elite Author
  • Author Level 10
  • Trendsetter
  • Top Monthly Author
+11 more
meta4creations
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!

3875 posts Community Moderator
  • Weekly Top Seller
  • Moderator
  • Envato Tuts+ Instructor
  • Netherlands
+10 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..

by
by
by
by
by
by