4594 posts Love & Light
    Has referred 500+ members Has sold $500,000+ on Envato Market Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+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 1 year 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));
4594 posts Love & Light
    Has referred 500+ members Has sold $500,000+ on Envato Market Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+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.

4594 posts Love & Light
    Has referred 500+ members Has sold $500,000+ on Envato Market Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+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 .

4594 posts Love & Light
    Has referred 500+ members Has sold $500,000+ on Envato Market Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+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:?

4594 posts Love & Light
    Has referred 500+ members Has sold $500,000+ on Envato Market Has collected 100+ items on Envato Market Elite Author: Sold more than $75,000 on Envato Market
+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!

3687 posts Community Moderator
    Has referred 10+ members Has sold $10,000+ on Envato Market Has been a beta tester for an Envato feature Has collected 1+ items on Envato Market
+9 more
Joost Envato team 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