问题是,当highcharts的historyData中有大量数据时,则仅每秒钟而不是毫秒显示一次数据放大。因此,在放大历史记录数据毫秒中包含大量数据的图表时,会丢失数据。
要重现该问题,请访问以下链接,然后在历史数据中存在大量数据后,将setinterval方法中的间隔从20更改为某个较大的数字20000,然后使用rangeselector放大历史数据,历史数据仅绘制了秒数据,但不是毫秒数据。
该问题在以下链接中转载: 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);
预期结果 :预期结果是在放大图表的historyData时还应绘制毫秒数据。
// 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>
答案 0 :(得分:1)
区别在于您的初始数据间隔为一秒:
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);