绘制从一个点到另一个点的垂直线的动画

时间:2013-03-08 08:22:32

标签: javascript jquery flot

我陷入了一些问题。你可能已经看过一个动画线,它在很多应用中就像一个扫描仪。那么我有类似的东西,但我需要它在图表中。

我真正需要的是我需要绘制一条自动从一点移动到另一点的垂直线。

让我再解释一下:  我有一个按钮  2.我按下按钮,图形区域出现。  3.在图形区域中,垂直线滚动该区域,就好像它正在扫描该区域一样。

我可以绘制线条,但它有点倾斜。其背后的逻辑如下:

for(i=0;i<frequencyArray.length;i++){
                 myTestArray2.push([i,outFrequencyArray[i]]);
            }

plot.setData([
              {data:myTestArray2,lines:{fill:false,lineWidth:3},shadowSize:10}
                    ]);

function setUpflot(){
            // setup plot

             //console.log("setUpflot");
             var options = {
                // series  : { shadowSize: 0, splines: {show:true,lineWidth:1}},
                 series  : { },

                 yaxis   : { ticks: 5, tickColor:"rgba(148,129,151,0.5)", min: minGraphY, max:maxGraphY,show: true},
                xaxis   : { tickLength:0,  show: false },
                grid    : { borderWidth:0,markings:[
                                {yaxis: { from: 200.0, to: 240.0 },color: "rgba(140,2,28,0.5)"}
                        ]}
             };

2 个答案:

答案 0 :(得分:6)

我昨天在回复评论时把它放在一起。

小提琴here

产地:

enter image description here

plot = $.plot($("#placeholder"),
  [ { data: someData} ], {
  series: {
    lines: { show: true }
  },
  crosshair: { mode: "x" }, // turn crosshair on
  grid: { hoverable: true, autoHighlight: false },
  yaxis: { min: -1.2, max: 1.2 }
});

crossHairPos = plot.getAxes().xaxis.min;
direction = 1;

setCrossHair = function(){
   if (direction == 1){
     crossHairPos += 0.5;   
   }
   else
   {
       crossHairPos -= 0.5;
   }
   if (crossHairPos < plot.getAxes().xaxis.min){
       direction = 1;
       crossHairPos = plot.getAxes().xaxis.min;
   }
   else if (crossHairPos > plot.getAxes().xaxis.max)
   {
       direction = 0;
       crossHairPos = plot.getAxes().xaxis.max;
   }
  plot.setCrosshair({x: crossHairPos})
  setTimeout(setCrossHair,100);
}

// kick it off
setTimeout(setCrossHair,100);

答案 1 :(得分:1)

var frequencyIndex = 0; //dynamic values stored intialised with 0.
var outFrequencyArray = [];

for(i=0;i<totalPoints;i++){

              outFrequencyArray.push(minGraphY-1);
          } 


opd=Math.tan(Math.PI/2);
outFrequencyArray.splice(frequencyIndex,0,opd);
frequencyIndex++;
for(i=0;i<frequencyArray.length;i++){
myTestArray2.push([i,outFrequencyArray[i]]);
        }

plot.setData([
          {data:myTestArray2,lines:{fill:false,lineWidth:3},shadowSize:10}
                ]);

function setUpflot(){
        // setup plot

         //console.log("setUpflot");
         var options = {
            // series  : { shadowSize: 0, splines: {show:true,lineWidth:1}},
             series  : { },

             yaxis   : { ticks: 5, tickColor:"rgba(148,129,151,0.5)", min: minGraphY, max:maxGraphY,show: true},
            xaxis   : { tickLength:0,  show: false },
            grid    : { borderWidth:0,markings:[
                            {yaxis: { from: 200.0, to: 240.0 },color: "rgba(140,2,28,0.5)"}
                    ]}
         };