0 Replies - 2495 Views - Last Post: 20 May 2013 - 08:27 AM

#1 tomas7470  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 54
  • Joined: 19-February 09

Tweenlite drawing charts.

Posted 20 May 2013 - 08:27 AM

Hello,
I write this code and trying to figure out why is that happening...
the object mcDraw should follow the chart animation but he is going up too much
and it appear to have an other line (circled in red) that shouldn't be there!!!
the picture:
Picture
this is the code:
import com.greensock.TweenLite;


var startX:Number = 10;
var startY:Number = 200;
var chartHeight:Number = 190;
var pointInterval:Number = 50;


var chartData:Array = [71,123,54,211,46,187];


var myChart:Shape = new Shape();
var lineAnim:Shape = new Shape();
addChild(lineAnim);
addChild(myChart);


drawChart();


function drawChart():void
{
    //myChart.graphics.clear();
    lineAnim.graphics.clear();
    Yaxis.text = String(mcDraw.y);
    Xaxis.text = String(mcDraw.x);
    lineAnim.x = startX;
    lineAnim.y = startY;


    lineAnim.graphics.lineStyle(2, 0x333333);
    
    lineAnim.graphics.moveTo(0, 0);
    lineAnim.graphics.lineTo(0, -chartHeight);
    lineAnim.graphics.moveTo(0, 0);
    lineAnim.graphics.lineTo((chartData.length - 1) * pointInterval, 0);
    
    lineAnim.graphics.lineStyle(1, 0x0099FF);
    
        //lineAnim.graphics.lineStyle(1, 0x0099FF);
        //lineAnim.graphics.moveTo(mcDraw.x, mcDraw.y);
        


    for (var n:int = 0 ; n < chartData.length ; n++)
    {
        var thisHeight:Number = chartData[n] * chartHeight / maxVal(chartData);
    
        if (n == 0)
        {
            //myChart.graphics.moveTo(pointInterval * n, 0 - thisHeight);
            lineAnim.graphics.moveTo(pointInterval * n, 0 - thisHeight);
        }
    
        //myChart.graphics.lineTo(pointInterval * n, 0 - thisHeight);
        TweenLite.to(mcDraw, 1, {x:pointInterval * n, y:0 - thisHeight, delay:n*1, overwrite:false, onUpdate:updateHandler});
        lineAnim.graphics.endFill();
    }
    
    function updateHandler():void
    {
     lineAnim.graphics.lineTo(mcDraw.x, mcDraw.y);
     lineAnim.graphics.moveTo(mcDraw.x, mcDraw.y);
    }
}


function maxVal(givenArray):Number
{
    var max = givenArray[0];
    
    for (var m:int = 0; m<givenArray.length; m++)
    {
        
        if (givenArray[m] > max)
        {
            max = givenArray[m];
        }
    }
    return max;
}

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1