gpt4 book ai didi

javascript - highchart plotline 可以有移动动画吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:27:49 26 4
gpt4 key购买 nike

有什么方法可以让plotline随着动画移动到新的位置吗?

还是我必须使用其他插件?

我想构建像二进制选项或专家选项游戏一样的乐趣。

这是我的简单演示: Sample demo link

$(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];

var hasPlotLine = false,
$button = $('#button'),
chart = $('#container').highcharts();

setInterval(function () {

chart.yAxis[0].removePlotLine('plot-line-1');

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

chart.yAxis[0].addPlotLine({
value: y,
color: 'red',
width: 2,
id: 'plot-line-1'
});
}, 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;
}())
}]

});

});

最佳答案

您可以使用animate 函数,它可以让您平滑地移动SVG 元素。将 translateY 参数设置为 y 的先前位置和当前位置之间的差值(toPixels 将值转换为像素)。

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: 50,
color: 'red',
width: 2,
id: 'plot-line-1'
});

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];

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


}, 1000);
}

例子:

关于javascript - highchart plotline 可以有移动动画吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39044463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com