2017-07-03 39 views
1

有没有办法让滚动最右边? 我试图在高图上进行实时更新,似乎有时候我遇到滚动被留下。继续滚动右边的高图

$(function() { 

    Highcharts.setOptions({ 
     global: { 
     useUTC: false 
} 
}); 

// Create the chart 
$('#container').highcharts('StockChart', { 
chart: { 
    events: { 
    load: function() { 

     // set up the updating of the chart each second 
     var series = this.series[0], 
     hasPlotLine = false, 
     $button = $('#button'), 
     chart = $('#container').highcharts(), 
     yAxis = chart.yAxis[0], 
     plotLine, 
     d, 
     newY; 

     yAxis.addPlotLine({ 
     value: 66, 
     color: 'red', 
     width: 2, 
     id: 'plot-line-1', 
        label: { 
       text: 66, 
       align: 'right', 
       y: newY, 
       x: 0 
      } 
     }); 

     setInterval(function() { 

     var x = (new Date()).getTime(), // current time 
      y = Math.round(Math.random() * 100); 
     series.addPoint([x, y], true, true); 

     plotLine = yAxis.plotLinesAndBands[0].svgElem; 

     d = plotLine.d.split(' '); 

     newY = yAxis.toPixels(y) - d[2]; 

     plotlabel = yAxis.plotLinesAndBands[0].label; 

        plotlabel.animate({ 
      translateY:newY, 
         text:y 
     },400), 


     plotLine.animate({ 
      translateY: newY 
     }, 400); 


     }, 1000); 
    } 
    } 
}, 

rangeSelector: { 
    buttons: [{ 
    count: 1, 
    type: 'minute', 
    text: '1M' 
    }, { 
    count: 5, 
    type: 'minute', 
    text: '5M' 
    }, { 
    type: 'all', 
    text: 'All' 
    }], 
    inputEnabled: false, 
    selected: 0 
}, 

title: { 
    text: 'Live random data' 
}, 

exporting: { 
    enabled: false 
}, 

series: [{ 
    name: 'Random data', 
    data: (function() { 
    // generate an array of random data 
    var data = [], 
     time = (new Date()).getTime(), 
     i; 

    for (i = -999; i <= 0; i += 1) { 
     data.push([ 
     time + i * 1000, 
     Math.round(Math.random() * 100) 
     ]); 
    } 
    return data; 
    }()) 
}] 

}); 

}); 

我知道这一点很难解释我的关心,但检查这一形象 enter image description here

我有搜索setExtremes但我不知道它是如何工作或如何将在成立未来的日期,以防万一这是我正在寻找的功能。

这里是的jsfiddle http://jsfiddle.net/kttfv1h3/3/

感谢您的帮助

回答