4509 posts Love & Light
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 7-8 years
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • South Africa
+3 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
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 1-2 years
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
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
outandouter says
this["point_mc"+n]._y = yAxis._y+yAxis._height;
this["point_mc"+n]._y -= yAxis._height*(Data[n]/(Max - Min));
4509 posts Love & Light
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 7-8 years
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • South Africa
+3 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.

4509 posts Love & Light
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 7-8 years
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • South Africa
+3 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
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
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 .

4509 posts Love & Light
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 7-8 years
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • South Africa
+3 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
  • Author had a Free File of the Month
  • Bought between 50 and 99 items
  • Exclusive Author
  • Has been a member for 4-5 years
  • Sold between 1 000 and 5 000 dollars
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:?

4509 posts Love & Light
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 7-8 years
  • Author had a File in an Envato Bundle
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • South Africa
+3 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!

3673 posts Community Moderator
  • Has been a member for 5-6 years
  • Contributed a Tutorial to a Tuts+ Site
  • Netherlands
  • Community Moderator
  • Envato Studio (Microlancer) Beta Tester
  • Sold between 10 000 and 50 000 dollars
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
+4 more
Joost Volunteer 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