4 Replies Latest reply on Jan 2, 2007 7:05 PM by mrgbement

    Multiple Line Graph

      First off, thanks to kglad for the line graph function I started with, it has been a huge help. Now the step I'm trying to take is 2 fold.

      First, I'd like to graph more than one line segment on the graph. Right now I am graphing functions f1 and f2, but f2 currently overwrites f1. I want them to coincide so f1 goes from x=1 to x=15, f2 goes from x=15 to x=25, f3 goes from x=25 to x=10 at a different y (these are all curves), and finally f4 goes from x=10 to x=1 creating a closed shape. Also, I want the x values and the y values to be variable based on the temperature. I'm using PV=nRT and n, R, and T are all known. so I have something like P=nRT/V where P is y, V is X and the nRT can be calculated for two steps of the 4. The other two steps are adiabatic, so Q=0, I don't know yet how to fit the lines but i do know that y = a / (x^(5/3)) is a formula that works, I just need to find the proper a values for steps 2 and 4.

      Part two of this issue is that currently the graph is drawing as the whole canvas, which is fine for testing until i get the multiple line part worked out; however I only want this to be 1/4 of the viewing area as I have other movie clips and such to put on this. A conceptual drawing of what I plan on making can be found at: http://www.students.bucknell.edu/gbement/Steps.html

      I'm a novice to Actionscript and movie clips, I previously did everything with motion tweens and nothing was dynamic. I plan on creating the piston and molecule simulation in another movie clip, then I can vary the play speed relative to the hot and cold temperatures by looping the movieclip and having it play faster for a high T and slower for a low T.

      Any help on any of my many issues would be greatly appreciated and the user will be recognized for their assistance in my research presentation :)
        • 1. Re: Multiple Line Graph
          arunbe Level 1
          Hi , this code may help you.
          • 2. Re: Multiple Line Graph
            mrgbement Level 1
            That certainly did help some. I'll try and combine the snippet you gave me with the one I found from kglad and if i figure it all out i'll have axis and graphs and it'll be pretty awesome. I'll post back with my progress and my code snippets if I get anywhere farther. Thanks a lot Arun!
            • 3. Re: Multiple Line Graph
              arunbe Level 1
              you are welcome... :)
              • 4. Re: Multiple Line Graph
                mrgbement Level 1
                Hi Arun, thanks again for the help but upon closer inspection (along with only a basic knowledge of java and actionscript), I think your script would need editing to work for me (editing i'm unsure of how to do). What I'm looking for is a graph that will create a line based on a function. Much like y=(a*b*c)/x or y=(a*b*c)/(x^1.66) The a*b*c would be complicated also, but here's what i've thought up on paper that I have to move to script, I hope this is useful:

                Step 1: Calculate the a*b*c
                The original function is PV=nRT , nRT being the a*b*c , however the Thot and Tcold terms are input boxes that the user types in before hitting the "go" button.

                So I have to do this much:
                tcold = Number(tcold_num.text);
                thot = Number(thot_num.text);
                var n:Number = 1;
                var R:Number = 0.0825;

                var a:Number;
                var b:Number;
                var c:Number;
                var d:Number;

                a = n*R*thot // Step 1 constant
                b = // Step 2 constant (formula to be finished :-/) Looks to be a formula using ((b) / (Math.pow(x, 1.666)))
                c = n*R*tcold // Step 3 constant
                d = // Step 4 constant (formula to be finished :-/)

                Then I need to find a way to initialize axis to line the graph, I can label the P and V axis using static text boxes later I suppose.
                The problem I have with yours that I don't understand is that I could add the function into the y part of the addLine() function, however it's noted as inity= y1 (requires a number), and the function definition has y1:Number.

                Now the issue i'm tackling below is just a newbie's lack of understanding (i hope), but the script kglad wrote (snipped below) will graph one line, and i can't figure out for the life of me how to write this up to graph more than one instance without overwritting the previous line. Again, Thanks for the help so far, it has helped me find the points where I lacked direction and solid ideas before.