我正在使用highcharts.js
问题是在创建图形时它向我显示两行而不是 一。
它应该只显示一行,因为它在两个值之间绘制图形 这是(时间戳和价值)。
请你检查一下为什么它向我显示两行而不是一行,我该如何解决这个问题:
(只需将代码复制并粘贴到文件中即可使用)。
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
</head>
<body style="background:#212224;">
<div id="container" style="max-width: 1666px; margin: 0 auto"></div>
<script type="text/javascript">
$.getJSON('https://dl.dropboxusercontent.com/u/76618626/data4.json', function (data) {
console.log("data size is : ");
console.log(data);
var data3 = [];
$.each(data.data,function(i,d){
console.log(new Date(d.timestamp).getTime(), d.value);
data3.push([new Date(d.timestamp).getTime(),d.value]);
});
console.log("Data 3 is :");
console.log(data3);
var data4 = [];
Highcharts.each(data3, function(p, i) {
if (typeof p[0] !== 'number' || typeof p[1] !== 'number') {
console.log('Invalid data is :')
console.log(p);
} else {
data4.push(p);
}
});
$('#container').highcharts({
chart: {
backgroundColor: '#000000',
},
title: {
text: 'Test Graph',
style: {
color: '#FFFFFF',
fontWeight: 'bold'
}
},
xAxis: {
type: 'datetime',
title: {
text: 'Time Stamp'
},
gridLineColor: 'grey',
gridLineWidth: 1,
lineWidth:1
},
yAxis: {
title: {
text: 'Value'
},
gridLineColor: 'grey',
gridLineWidth: 1,
lineWidth:1
},
legend: {
enabled: true
},
exporting: false,
plotOptions: {
line: {
lineColor: 'red',
fillOpacity: 1,
lineWidth: 2,
states: {
hover: {
lineWidth: 2
}
},
threshold: null,
marker: {
fillColor: '#e57255'
}
},
},
series: [{
type: 'line',
name: 'test',
data: data4
}]
});
});
</script>
</body>
</html>