gpt4 book ai didi

javascript - Highcharts 的历史数据中不存在毫秒数据

转载 作者:行者123 更新时间:2023-12-02 23:27:42 25 4
gpt4 key购买 nike

问题是,当 highcharts 的历史数据中有大量数据时,放大数据仅每秒出现,而不是毫秒。因此,在放大历史数据中包含大量数据的图表时,毫秒数据会丢失。

要重现该问题,请访问下面的链接,然后当历史数据中存在大量数据时,将 setinterval 方法中的间隔从 20 更改为某个大数字 20000,然后使用范围选择器放大历史数据,历史数据只有绘制了秒数据,但未绘制毫秒数据。

该问题在以下链接中重现: https://jsfiddle.net/nh5ap21m/

访问了highcharts的api文档:https://api.highcharts.com/highcharts/plotOptions.series.pointInterval并尝试对pointInterval、pointIntervalUnit、connectNulls、gapSize、gapUnit进行更改,但仍然找不到确切的解决方案。

此处更改间隔:

setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100);
series1.addPoint([x, y], true, true);
}, 20);
var series2 = this.series[1];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 50);
series2.addPoint([x, y], true, true);
}, 20);

预期结果:预期结果是当放大图表的历史数据时,还应该绘制毫秒数据。

// Create the chart
Highcharts.stockChart('container', {
chart: {
events: {
load: function () {

// set up the updating of the chart each second
var series1 = this.series[0];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 100);
series1.addPoint([x, y], true, true);
}, 20);
var series2 = this.series[1];
setInterval(function () {
var x = (new Date()).getTime(), // current time
y = Math.round(Math.random() * 50);
series2.addPoint([x, y], true, true);
}, 20);
}
}
},

time: {
useUTC: false
},

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
},
legend: {
enabled: true
},
plotOptions: {
series: {
marker: {
states: {
hover: {
enabled: true,
animation: {duration: 100},
enableMouseTracking: true,
stickyTracking: true
}
}
}
}
},

tooltip:{
shared: true,
split: false,
stickyTracking: true,
enableMouseTracking: true,
enabled: true,
followPointer: true,
followTouchMove: true,
formatter: function(){
var tooltip = "";
var phaseNameList = "";

//tooltip += "<b>I-unit "+ "<br/>"+ "x: "+this.x +"</b>";
tooltip += "<b>I-unit "+ "<br/>"+ "x: "+ new Date(this.x)+
"</b>";
tooltip += "<br/>"+ "y: "+this.y +"</b>";
tooltip += "<br/>"+ this + "</b>";
return tooltip;
}
},

series: [{
name: 'Random data1',
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;
}())
},
{
name: 'Random data2',
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() * 50)
]);
}
return data;
}())
}]
});
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/stock/modules/exporting.js"></script>
<script src="https://code.highcharts.com/stock/modules/export-data.js"></script>

<div id="container" style="height: 400px; min-width: 310px"></div>

最佳答案

不同之处在于您的初始数据具有一秒的间隔:

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

动态添加的数据间隔为20毫秒:

setInterval(function() {
var x = (new Date()).getTime(), // date every 20 milliseconds
y = Math.round(Math.random() * 50);
series2.addPoint([x, y], true, true);
}, 20);

关于javascript - Highcharts 的历史数据中不存在毫秒数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56662558/

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