Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3:线图有问题_Actionscript 3_Flash_Actionscript_Graph_Vector - Fatal编程技术网

Actionscript 3 AS3:线图有问题

Actionscript 3 AS3:线图有问题,actionscript-3,flash,actionscript,graph,vector,Actionscript 3,Flash,Actionscript,Graph,Vector,我写的一些代码有点问题。基本上,它所做的是取3个不断变化的值,并以累积线图的形式绘制它们随时间的变化图。它几乎起作用了,除了我在整个舞台上画了一条奇怪的线,而且我不知道问题是什么。完整的代码如下,您可以通过将其粘贴到flash中来运行它 import flash.display.Shape; import flash.display.MovieClip; import flash.display.Sprite; import flash.utils.Timer; var y1:Array =

我写的一些代码有点问题。基本上,它所做的是取3个不断变化的值,并以累积线图的形式绘制它们随时间的变化图。它几乎起作用了,除了我在整个舞台上画了一条奇怪的线,而且我不知道问题是什么。完整的代码如下,您可以通过将其粘贴到flash中来运行它

import flash.display.Shape;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.utils.Timer;

var y1:Array = new Array();
var y2:Array = new Array();
var y3:Array = new Array();
var avg:Array = new Array();

var y1Shape:Shape = new Shape();
var y2Shape:Shape = new Shape();
var y3Shape:Shape = new Shape();
var avgShape:Shape = new Shape();

var container:Sprite = new Sprite();

var scale:uint = 1;

var redrawGraph:int = setInterval(reDraw,500);

var y1Int:int = 0;
var y2Int:int = 0;
var y3Int:int = 0;

container.addChild(y1Shape);
container.addChild(y2Shape);
container.addChild(y3Shape);
container.addChild(avgShape);
this.addChild(container);

function reDraw():void
{
    y1Shape.graphics.clear();
    y2Shape.graphics.clear();
    y3Shape.graphics.clear();
    avgShape.graphics.clear();

    y1Shape.graphics.lineStyle(1, 0x0066FF, 1);
    y1Shape.graphics.beginFill(0x0066FF, 0.5);
    y2Shape.graphics.lineStyle(1, 0x009900, 1);
    y2Shape.graphics.beginFill(0x009900, 0.5);
    y3Shape.graphics.lineStyle(1, 0x990000, 1);
    y3Shape.graphics.beginFill(0x990000, 0.5);
    avgShape.graphics.lineStyle(1, 0x000000, 1);

    y1Int = rand();
    y2Int = rand();
    y3Int = rand();

    trace(y1Int, y2Int, y3Int);

    y1.unshift(y1Int);
    y2.unshift(y2Int);
    y3.unshift(y3Int);
    popOut(y1);
    popOut(y2);
    popOut(y3);

    var i:uint,sum:uint,aLength:uint,len:uint = y1.length,max:int = 0,height_:int = 400;
    scale = 10;
    for (i=0; i<len; i++)
    {
        max = Math.max(y1[i] + y2[i] + y3[i],max);
    }

    for (i=0; i<len; i++)
    {
        sum +=  y1[i] + y2[i] + y3[i];
    }

    avg.unshift(Math.round(sum/len));

    /*--------------------------------MATCHED GRAPH------------------------------------------*/
    var y1_commands:Vector.<int> = new Vector.<int>();
    var y1_coord:Vector.<Number>= new Vector.<Number>();
    var y1_coord_rev:Vector.<Number> = new Vector.<Number>();
    y1_commands.push(1);
    y1_coord.push(400,height_);

    for (i=0; i<len; i++)
    {
        y1_commands.push(2);
        y1_coord.push((400-i*scale),height_-(Math.round((y1[i]/max)*height_)));
        y1_coord_rev.unshift((400-i*scale),height_-(Math.round((y1[i]/max)*height_)));
    }
    for (i=len; i>0; i--)
    {
        y1_commands.push(2);
        y1_coord.push(400 - i*scale,height_);
    }
    y1_commands.push(2);
    y1_coord.push(400,height_);

    /*--------------------------------MATCHED GRAPH------------------------------------------*/

    /*----------------------------------BUSY GRAPH-------------------------------------------*/
    var y2_commands:Vector.<int> = new Vector.<int>();
    var y2_coord:Vector.<Number>= new Vector.<Number>();
    var y2_coord_rev:Vector.<Number> = new Vector.<Number>();
    y2_commands.push(1);
    y2_coord.push(400,height_-(Math.round((y1[i]/max)*height_)));

    for (i=0; i<len; i++)
    {
        y2_commands.push(2);
        y2_coord.push((400-i*scale),height_-(Math.round(((y1[i]+y2[i])/max)*height_)));
        y2_coord_rev.unshift((400-i*scale),height_-(Math.round(((y1[i]+y2[i])/max)*height_)));
    }
    for (i=len; i>0; i--)
    {
        y2_commands.push(2);
        y2_coord.push(400 - i*scale, height_-(Math.round((y1[i]/max)*height_)));
    }
    y2_commands.push(2);
    y2_coord.push(400,height_-(Math.round((y1[i]/max)*height_)));

    /*----------------------------------BUSY GRAPH-------------------------------------------*/

    /*----------------------------------VAC GRAPH-------------------------------------------*/
    var y3_commands:Vector.<int> = new Vector.<int>();
    var y3_coord:Vector.<Number>= new Vector.<Number>();
    var y3_coord_rev:Vector.<Number> = new Vector.<Number>();
    y3_commands.push(1);
    y3_coord.push(400,height_-(Math.round(((y1[i]+y2[i])/max)*height_)));

    for (i=0; i<len; i++)
    {
        y3_commands.push(2);
        y3_coord.push((400-i*scale),height_-(Math.round(((y1[i]+y2[i]+y3[i])/max)*height_)));
        y3_coord_rev.unshift((400-i*scale),height_-(Math.round(((y1[i]+y2[i]+y3[i])/max)*height_)));
    }
    for (i=len; i>0; i--)
    {
        y3_commands.push(2);
        y3_coord.push(400 - i*scale, height_-(Math.round(((y1[i]+y2[i])/max)*height_)));
    }
    y2_commands.push(2);
    y2_coord.push(400,height_-(Math.round(((y1[i]+y2[i])/max)*height_)));

    /*----------------------------------BUSY GRAPH-------------------------------------------*/
    //y3Shape.graphics.drawPath(y3_commands, y3_coord);
    y2Shape.graphics.drawPath(y2_commands, y2_coord);
    y1Shape.graphics.drawPath(y1_commands, y1_coord);

}

function popOut(a:Array):void
{
    if (a.length >=Math.ceil(400/scale))
    {
        a.pop();
    }
}

function rand():int
{
    return Math.floor(Math.random() * (1 + 5 - 0) + 0);
}
导入flash.display.Shape;
导入flash.display.MovieClip;
导入flash.display.Sprite;
导入flash.utils.Timer;
变量y1:Array=新数组();
变量y2:Array=newarray();
变量y3:Array=新数组();
var avg:Array=new Array();
变量y1Shape:Shape=新形状();
变量y2Shape:Shape=新形状();
var y3Shape:Shape=新形状();
var avgShape:Shape=新形状();
变量容器:Sprite=新Sprite();
风险等级:uint=1;
变量重绘图:int=setInterval(重绘,500);
变量y1Int:int=0;
变量y2Int:int=0;
变量y3Int:int=0;
container.addChild(y1Shape);
container.addChild(y2Shape);
container.addChild(y3Shape);
container.addChild(avgShape);
这个.addChild(容器);
函数reDraw():void
{
y1Shape.graphics.clear();
y2Shape.graphics.clear();
y3Shape.graphics.clear();
avgShape.graphics.clear();
y1Shape.graphics.lineStyle(1,0x0066FF,1);
y1Shape.graphics.beginll(0x0066FF,0.5);
y2Shape.graphics.lineStyle(1,0x009900,1);
y2Shape.graphics.beginll(0x009900,0.5);
y3Shape.graphics.lineStyle(0x990000,1);
y3Shape.graphics.Beginll(0x990000,0.5);
avgShape.graphics.lineStyle(1,0x000000,1);
y1Int=rand();
y2Int=rand();
y3Int=rand();
跟踪(y1Int、y2Int、y3Int);
y1.取消移位(y1Int);
y2.取消移位(y2Int);
y3.取消移位(y3Int);
弹出(y1);
弹出(y2);
弹出(y3);
变量i:uint,和:uint,长度:uint,长度:uint=y1。长度,最大值:int=0,高度:int=400;
比例=10;

对于(i=0;i,如果在
.drawPath
附近插入跟踪向量,您将看到如下内容:

trace(y2_commands); // 1,2,2,2,2
trace(y2_coord); // 400,171,400,57,390,NaN,400,171,400,57
所以,NaN(不是一个数字)意味着,在计算坐标时有错误


ps.
y1[i]
在忙图的第一次计算中未定义,当您绘制一条没有循环的路径时,Flash要求您的路径被循环,以便用某些东西填充。因此,它通过向起点添加一条线并填充来隐式循环。为了获得一条不重叠的路径,请在路径上添加两个点,这两个点将位于X轴上0点的正下方,一个点位于X轴上最后一个点的正下方你的图,在图上第一个点的正下方

实际上,您已经安装了它们,但出于某种原因,您放置的不是2个点,而是大量em,并且该行的高度位置显然是错误的。您的代码说明:

for (i=len; i>0; i--)
{
    y2_commands.push(2);
    y2_coord.push(400 - i*scale, height_-(Math.round((y1[i]/max)*height_)));
}
你应该:

for (i=len; i>0; i--)
{
    y2_commands.push(2);
    y2_coord.push(400 - i*scale, height_);
}
或者更好:

y2_commands.push(2);
y2_commands.push(2);
y2_coord.push(400 - len*scale, height_);
y2_coord.push(400, height_);

我的代码包括
-(Math.round((y1[i]/max)*height_uz))
的原因是,第二个“级别”的底部不会与第一个“级别”重叠,它们有效地相互堆叠。您可以通过更改addChild()来实现这一点一旦你解决了问题,你的图的顺序就会确定。此外,你已经有了一个y1_coord_rev coords数组,从那里添加它们!谢谢,这让我找到了问题所在,返回循环(从右到左,最初从左到右绘制)从数组外的一个点开始,现在工作得很好!还感谢你选择了
y1[i]
问题。