Visualizzazione dei risultati da 1 a 3 su 3

Discussione: grafici a barre

  1. #1

    grafici a barre

    Salve a tutti,
    ho un problema con un action script, che genera un grafico a barre.

    Il problema è che non riesco a far visualizzare il valore di ogni barra sopra la stessa, con zone di testo variabili.

    l'action è questo

    [I]
    // make a 100-pixel grid movieclip at depth 1
    lv= new LoadVars();

    var color:Array= new Array(0x0066cc,0x999900,0x660099,0xcc0099,0x339900 ,0x00ff1e,0xea00ff,0x4926D9,0xFF0000,0x4498BB);
    var len:Number= color.length;
    var rnd:Number= Math.floor(Math.random()*len);
    var randomColor= color[rnd];

    var format:TextFormat = new TextFormat();
    format.align = "justify";
    format.color = 0x00ff00;
    format.size = 14;


    var nrSum:Number = 0;
    //gradient fill data

    fillType = "linear";
    colors = [0xffffff, color[Number(Math.floor(Math.random()*len))]];
    alphas = [100, 100];
    ratios = [127, 255];
    matrix = {matrixType:"box", x:30, y:50, w:30, h:30, r:0/180*Math.PI};

    //end data gradient fill

    createEmptyMovieClip("grid", 1);
    grid.lineStyle(1, 0xcccccc, 100);
    grid.moveTo(5, 5);
    grid.lineTo(795, 5);
    grid.lineTo(795, 400);
    grid.lineTo(5, 400);
    grid.lineTo(5, 5);
    grid.moveTo(100, 5);
    grid.lineTo(100, 400);
    grid.moveTo(200, 5);
    grid.lineTo(200, 400);
    grid.moveTo(300, 5);
    grid.lineTo(300, 400);
    grid.moveTo(400, 5);
    grid.lineTo(400, 400);
    grid.moveTo(500, 5);
    grid.lineTo(500, 400);
    grid.moveTo(600, 5);
    grid.lineTo(600, 400);
    grid.moveTo(700, 5);
    grid.lineTo(700, 400);
    grid.moveTo(800, 5);
    grid.lineTo(800, 400);
    grid.moveTo(5, 100);
    grid.lineTo(795, 100);
    grid.moveTo(5, 200);
    grid.lineTo(795, 200);
    grid.moveTo(5, 300);
    grid.lineTo(795, 300);
    grid.moveTo(5, 400);
    grid.lineTo(795, 400);

    xinit=0;
    x1=30;
    y1=1;



    // create a movieclip of two rectangles at depth 2
    // create a variable r to reference this movieclip
    // (which we can do because createEmptyMovieClip returns a
    // reference to itself)
    var r:MovieClip = createEmptyMovieClip("rectangles", 2);
    //r.beginFill(0xcc00cc, 100);
    //r.moveTo(30, 400);
    //r.lineTo(50, 400);
    //r.lineTo(50, 350);
    //r.lineTo(30, 350);
    // notice that the shape will be filled automatically
    // without having to draw the last line
    //r.endFill();
    // start a new rectangle of a different color in the same clip
    //r.beginFill(0x0000cc, 50);
    //r.lineStyle(1, 0x000033, 100);
    //r.moveTo(60, 400);
    //r.lineTo(80, 400);
    //r.lineTo(80, 180);
    //r.lineTo(60, 180);
    //r.endFill();

    //var height:Array = new Array();
    //for (var i:Number = 0; i < 10; i++) {
    // height[i] = (i + 5) ;
    //}


    lv.onLoad = function(success:Boolean):Void {
    if (success) {
    // make arrays out of each of the passed strings
    var nr:Array = lv.nr.split(",");
    //var color:Array = this.color.split(",");
    for (var i:Number=0; i < nr.length; i++) {
    nrSum +=Number(nr[i]);
    lv.push({
    nr:Number(nr[i])
    //colorarseInt(color[i], 16)
    })

    }

    }


    var height:Array = new Array();
    for (var i:Number = 0; i < 10; i++) {
    height[i] = (i + 5) ;
    }



    for (j=0; j < nr.length; j++) {
    //draw column
    r.beginFill(color[Number(Math.floor(Math.random()*len))], 50);
    //r.beginGradientFill(fillType, colors, alphas, ratios, matrix);
    r.lineStyle(1, 0xffffff, 100);
    r.moveTo(xinit+j*45, 400);
    r.lineTo(x1+j*45, 400);
    r.lineTo(x1+j*45, 400-Number(nr[j]) * 20);
    r.lineTo(xinit+j*45, 400-Number(nr[j]) * 20);
    r.endFill();
    //trace("nr"+" "+j+" "+Number(nr[j]));
    //r.createTextField("moreinfo"+j, this.getNextHighestDepth(), xinit+j*30, Number(nr[j])*20-20, 10, 10);
    //tFormat.color = 0x000000;
    //this["moreinfo"+j].setNewTextFormat(tFormat);

    //this["moreinfo"+j].text=nr[j];

    }


    for (i=1; i<=10; i++) {

    createTextField("moreinfo" + i, this.getNextHighestDepth(), (i*30), (height*20 -20), 40, 30);
    tFormat.color = 0x00ff00;
    this["moreinfo" + i].setNewTextFormat(tFormat);
    this["moreinfo" + i].text=20+i*30;
    trace(20+i*30);


    }


    }

    lv.load("textfiles/piechartsampledata_1.txt");



    valori vengono presi da un file di testo che contiene questa stringa
    &nr=1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1&

    dove sta l'errore???

  2. #2
    tempo fa ho fatto un semplice istogramma usando sempre il file di testo x i valori

    codice:
    stop();
    rett1._height =0;
    rett2._height =0;
    rett3._height =0;
    rett4._height =0;
    rett5._height =0;
    System.useCodepage=true;
    myText = new LoadVars();
    myText.onLoad = function(success) {
    	if (success) {    
    		val = myText.dim1;	
    		perc1=val+"%";
    		trace(val);
       rett1.onEnterFrame = function(){
    	if (this._yscale <= val){
    	this._yscale++;
    	} else	{
    	delete this.onEnterFrame
    	}
    	}
    	val2 = myText.dim2;	
    	perc2=val2+"%";
       rett2.onEnterFrame = function(){
    	if (this._yscale <= val2){
    	this._yscale++;
    	} else	{
    	delete this.onEnterFrame
    	}
    	}	
        val3 = myText.dim3;	
    	perc3=val3+"%";
       rett3.onEnterFrame = function(){
    	if (this._yscale <= val3){
    	this._yscale++;
    	} else	{
    	delete this.onEnterFrame
    	}
    	}	
    val4 = myText.dim4;	
    perc4=val4+"%";
    trace(val4);
       rett4.onEnterFrame = function(){
    	if (this._yscale <= val4){
    	this._yscale++;
    	} else	{
    	delete this.onEnterFrame
    	}
    	}
    val5 = myText.dim5;	
    perc5=val5+"%";
       rett5.onEnterFrame = function(){
    	if (this._yscale <= val5){
    	this._yscale++;
    	} else	{
    	delete this.onEnterFrame
    	}
    	}
    	}
    };
    myText.load("dati.txt");
    nel file di testo
    &dim1=30&dim2=40&dim3=10&dim4=100&dim5=65&


    sullo stage 5 clip istanziate
    rett1, rett2,......, rett5

    e sotto gli stessi clip delle caselle di testo in cui ci metto il valore
    con var perc1,perc2,......., perc5

    la verità non è una meretrice che si getta al collo di chi non la vuole ma anzi essa è dotata di una così altera bellezza che anche chi sacrifica tutto per ottenerla non è sicuro di averla raggiunta !

  3. #3
    ciao,
    grazie per la risposta ma il tuo metodo non fa al caso mio, perchè legge i valori che tu gli passi, invece io ho bisogno che i grafici vengono creati mediante delle variabili.

    tu sai gia quante variabili hai, mentre io no. una volta potrebbero essere 2, una volta 20...

    io dovrei creare delle zone di testo dinamiche, in un movie clip diverso, perche se ho due valori devo solo fare 2 zone di testo, se ne ho 20 ne devo fare 20.... spero di essermi spiegato al meglio.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.