• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

adobe flash strip graph

I'm trying to write a strip graph using ActionScript.  I'm wondering the best way to code this.  I'm assuming I setup a background with the X and Y access and then continually redraw a line across this surface.
0
PeterTrefren
Asked:
PeterTrefren
  • 3
  • 2
1 Solution
 
GabriologistCommented:
I'm assuming that the graph you are trying to create is like this - http://www.nzmaths.co.nz/category/glossary/strip-graph ?

To build something like this I would have several rectangular movieclips in the Library - as many as the number of sets of data that you want to show

I would then define an origin to the graph in terms of the '0' point on the x axis - and set it to the x position on the stage that I want it to appear at (I'll call this variable 'xAxisStart')

I'd then place the rectangle that represents the first set of data at xAxisStart, then change its width property so that it shows the correct share. Let's call that width 'xWidth1'.

This now means that the start of the 2nd part of the strip would have a starting x position given by

xAxisStart + xWidth1

So you set the 2nd rectangle's x position to this value, then change its width property to reflect its share of the data - let's call that 'xWidth2'.

Next start point (for the third rectangle) becomes

xAxisStart + xWidth1 + xWidth2

... and so on. (if you see the pattern that's building here)
0
 
PeterTrefrenAuthor Commented:
No I'm looking for something that looks like when you get an EKG.
0
 
GabriologistCommented:
Ah, ok...

Do you want the 'drawing point' (the place where the drawing appears) to be static, and the previously drawn parts to move off to the left?

Or do you want the whole drawing to remain static and the pen / drawing point to move to the right as new stuff is drawn?

And do you want the drawing to simulate data - i.e. you give it different data and you get a different trace?
Or does is just need to be random data?
Or does is just need to be an animation and show the same thing every time? (In which case actionscript may not be the best way to achieve this).
0
 
PeterTrefrenAuthor Commented:
I believe what I'm looking for is the first one you described.  What I want is to setup an X axis with time and a Y axis with something like price.  On the left side of the grid (time = 0) you would add a point representing the price at the present time.  As time elapsed the point would move to the right everything else stays fixed.  As more points were added it looks like you have a line scrolling across a grid to the right.  In my example the X axis would represent the relative time passed from when the price was posted.  The points are determined by user input so this is a dynamic representation.
0
 
GabriologistCommented:
Ok. Here's the approach I would take.

Create an empty movieclip, place it on the stage and give it the instance name of 'ticker'.

To draw the line I would be using the Flash drawing api - http://flash-creations.com/notes/dynamic_drawingapi.php - specifically the 'lineTo' function, though you'll need to use the 'moveTo' first to set the starting point for the line. The x coordinate of your lineTo command would be determined by your time factor, and the y coordinate by your price. The smaller your timeslices, the more your drawn lines will approximate curves rather than straight lines.

The drawing should be done *inside* the empty movieclip on the stage.

Now, when the drawing line reaches the point where you want it to be fixed, then you *start moving* the movieclip on the stage. If you use the same 'time' offset to move the movieclip as you were using to do your lineTo commands, then the 'drawing point' should stay fixed, while the whole drawn line continues to scroll.

I hope all of that makes sense!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now