[thelist] flash line chart

Liam Delahunty ldelahunty at britstream.com
Thu Aug 29 12:15:00 CDT 2002


spent the day reinventing the wheel so thought I'd share... I'm sure it
could be improved *big time* but this'll do for now.

I'll probably post something to www.liamdelahunty.com/tips/ when/if I have a
more decent version with titles etc

If it's of any use to you please feel free to use it, I hereby release it
under the GNU General Public License.

It'd be nice to be informed of any "real uses", I'll create a page of links
somewhere...

Kind regards,
Liam Delahunty

// feedback and suggestions to ldelahunty at britstream.com
linea = new Array("35", "16", "45", "084", "095", "060", "050", "065",
"085", "075", "045", "015", "25", "35", "065");
lineb = new Array("22", "30", "50", "65", "85", "75", "45", "15", "125",
"35", "65", "86", "9", "90", "84");
counta = linea.length;
maxa = 0;
maxb = 0;
for (indexx=0; indexx<counta; indexx++) {
	maxa = math.max(maxa, linea[indexx]);
	maxb = math.max(maxb, lineb[indexx]);
}
highval = math.max(maxa, maxb);
var stageheight = Stage.height;
var stagewidth = Stage.width;
var marginleft = 50;
var marginright = 50;
var marginbottom = 50;
var margintop = 50;
// set limits
var originx = marginleft;
var originy = stageheight-marginbottom;
var availx = (stagewidth-marginleft)-marginright;
var availy = (stageheight-marginbottom)-margintop;
var maxx = stagewidth-marginright;
// get each value in each array and translate it to ratio of
// highval to make max use of space. // hr = height ratio
var hr = availy/highval;
ha = new Array();
hb = new Array();
for (i=0; i<counta; i++) {
	if (hr>1) {
		ha[i] = linea[i]*hr;
		hb[i] = lineb[i]*hr;
	} else {
		ha[i] = linea[i]/hr;
		hb[i] = lineb[i]/hr;
	}
}
// increments
// x is available width / count + 1;
xinc = availx/(counta);
_root.createEmptyMovieClip("amovie", 1);
with (_root.amovie) {
	// first set up inital values
	var x_a = originx;
	var y_a = originy;
	var x_b = originx;
	var y_b = originy;
	// draw grid
	// 8 horizontal lines (0-8)
	for (i=0; i<9; i++) {
		lineStyle(1, 0xcccccc, 100);
		moveTo(x_a, y_a);
		lineTo(maxx, y_a);
		y_a = y_a-(availy/8);
	}
	//	reset up inital values
	var x_a = originx;
	var y_a = originy;
	// height of the chart
	for (indexa=0; indexa<(counta+1); indexa++) {
		lineStyle(1, 0xcccccc, 100);
		moveTo(x_a, y_a);
		lineTo(x_a, margintop);
		x_a = x_a+xinc;
	}
	//	reset up inital values
	var x_a = originx;
	var y_a = originy;
	// now get each result from the arrays
	for (indexa=0; indexa<counta; indexa++) {
		lineStyle(1, 0x009933, 100);
		moveTo(x_a, y_a);
		x_a = x_a+xinc;
		y_a = originy-ha[indexa];
		lineTo(x_a, y_a);
		// second line
		lineStyle(2, 0x3333cc, 100);
		moveTo(x_b, y_b);
		x_b = x_b+xinc;
		y_b = originy-hb[indexa];
		lineTo(x_b, y_b);
	}
}




More information about the thelist mailing list