A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Line Charts, Bar Charts?

  1. #1
    Senior Member
    Join Date
    Mar 2008
    Posts
    168

    Line Charts, Bar Charts?

    I need to learn how to create dynamic line and bar charts in Flash AS2. Anything that reads txt or xml data files or internal arrays. The server I am working on is rather limited..... no php, asp and the like. Does anyone know where I can find a tutorial that may help? FlashKit has never failed me before!

    Thanks
    Adam

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    DOWNLOAD EXAMPLE FILE

    made the above a while ago for school, just for fun, instead of using Excel

    Look at Frame Actions for Layer 1 Frame, replace the names array and for loop, with one of these codes:

    - TEXT FILE -

    Frame Code:

    Actionscript Code:
    loadText = new LoadVars();
    loadText.onLoad = function(success){
        if(success){
            names = [
            ["Spania", this.bar1_1, this.bar1_2],
            ["Hellas", this.bar2_1, this.bar2_2],
            ["Litauen", this.bar3_1, this.bar3_2],
            ["Slovakia", this.bar4_1, this.bar4_2],
            ["Latvia", this.bar5_1, this.bar5_2],
            ["Irland", this.bar6_1, this.bar6_2],
            ["Portugal", this.bar7_1, this.bar7_2],
            ["Italia", this.bar8_1, this.bar8_2],
            ["Ungarn", this.bar9_1, this.bar9_2],
            ["Polen", this.bar10_1, this.bar10_2],
            ["Frankrike", this.bar11_1, this.bar11_2],
            ["Sverige", this.bar12_1, this.bar12_2],
            ["Estland", this.bar13_1, this.bar13_2],
            ["Storbritannia", this.bar14_1, this.bar14_2],
            ["Finland", this.bar1_15, this.bar15_2]
            ];
           
            for(i=0;i<names.length;i++){
                _root["m"+(i+1)].txt.text = names[i][0];
                _root["m"+(i+1)].a1 = names[i][1];
                _root["m"+(i+1)].a2 = names[i][2];
            }
        } else {
            // error loading text file
        }
    }
    loadText.load("stats.txt");

    This will load variables from a text file (stats.txt), and distribute them to each bar (my sample file has 2 bars for each country). Your text file would look something like this for the above code:

    Code:
    &bar1_1=45.0&bar1_2=20.8&
    &bar2_1=15.2&bar2_2=55.2&
    &bar3_1=90.5&bar3_2=53.4&
    &bar4_1=02.0&bar4_2=35.5&
    &bar5_1=38.6&bar5_2=76.6&
    &bar6_1=23.0&bar6_2=97.7&
    &bar7_1=29.0&bar7_2=24.8&
    &bar8_1=45.7&bar8_2=25.8&
    &bar9_1=99.0&bar9_2=37.1&
    &bar10_1=33.8&bar10_2=37.2&
    &bar11_1=52.0&bar11_2=78.3&
    &bar12_1=46.2&bar12_2=22.0&
    &bar13_1=47.0&bar13_2=11.8&
    &bar14_1=21.3&bar14_2=15.0&
    &bar15_1=11.2&bar15_2=89.0&
    - XML FILE -

    Frame Code:

    Actionscript Code:
    xml = new XML();
    xml.ignoreWhite = true;
    xml.onLoad = function(success){
        if(success){
            names = new Array();
            countries = ["Spania", "Hellas", "Litauen", "Slovakia", "Latvia", "Irland", "Portugal", "Italia", "Ungarn", "Polen", "Frankrike", "Sverige", "Estland", "Storbritannia", "Finland"];
           
            node = this.firstChild.childNodes;
            for(j=0;j<node.length;j++){
                barX_1 = Number(node[j].childNodes[0].firstChild.toString());
                barX_2 = Number(node[j].childNodes[1].firstChild.toString());
                names.push(new Array(countries[j], barX_1, barX_2));
            }
           
            for(i=0;i<names.length;i++){
                _root["m"+(i+1)].txt.text = names[i][0];
                _root["m"+(i+1)].a1 = names[i][1];
                _root["m"+(i+1)].a2 = names[i][2];
            }
        } else {
            // error loading xml file
        }
    }
    xml.load("http://pridspeed.com/stats.xml");

    and your XML file would look something like this for the above code:

    Code:
    <stats>
    	<bar>
    		<bar1>25.2</bar1>
    		<bar2>13.4</bar2>
    	</bar>
    	<bar>
    		<bar1>22.4</bar1>
    		<bar2>86.5</bar2>
    	</bar>
    	<bar>
    		<bar1>21.1</bar1>
    		<bar2>09.1</bar2>
    	</bar>
    	<bar>
    		<bar1>11.1</bar1>
    		<bar2>97.0</bar2>
    	</bar>
    	<bar>
    		<bar1>75.2</bar1>
    		<bar2>84.8</bar2>
    	</bar>
    	<bar>
    		<bar1>66.6</bar1>
    		<bar2>34.2</bar2>
    	</bar>
    	<bar>
    		<bar1>22.5</bar1>
    		<bar2>52.2</bar2>
    	</bar>
    	<bar>
    		<bar1>77.1</bar1>
    		<bar2>22.1</bar2>
    	</bar>
    	<bar>
    		<bar1>91.0</bar1>
    		<bar2>01.3</bar2>
    	</bar>
    	<bar>
    		<bar1>52.2</bar1>
    		<bar2>22.5</bar2>
    	</bar>
    	<bar>
    		<bar1>13.5</bar1>
    		<bar2>47.8</bar2>
    	</bar>
    	<bar>
    		<bar1>25.6</bar1>
    		<bar2>63.8</bar2>
    	</bar>
    	<bar>
    		<bar1>22.9</bar1>
    		<bar2>52.2</bar2>
    	</bar>
    	<bar>
    		<bar1>89.9</bar1>
    		<bar2>17.1</bar2>
    	</bar>
    	<bar>
    		<bar1>18.2</bar1>
    		<bar2>79.8</bar2>
    	</bar>
    </stats>
    -------------------

    Hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Senior Member
    Join Date
    Mar 2008
    Posts
    168
    Thanks dear friend, looks very clean.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center