Highcharts test tool
HTML
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://cdn.pubnub.com/pubnub-3.16.5.min.js"></script>
<div id="container"></div>
<button id="stop">Stop</button>
<span id="stream">test</span>
JavaScript
var chart1=Highcharts.chart('container',{
chart: {
type: 'spline',
events: {
load: function () {
}
}
},
title: {
text: 'PubNub Stock data demo'
},
xAxis: {
type: 'datetime',
tickPixelInterval: 50
},
yAxis: {
title: {
text: 'Value'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
series: [{
marker: {
enabled: true
},
data: null
}]
});
var pubnub = PUBNUB.init({
publish_key: 'pub-c-368fa61a-3fee-4d62-bb5d-6b5b41ce0e55',
subscribe_key: 'sub-c-70f0e22c-93c7-11e7-96ff-be2ded2a9039',
error: function (error) {
document.getElementById("stream").innerHTML='Error: ';
document.getElementById("stream").innerHTML+=error;
}
});
pubnub.subscribe({
channel : 'Beehive_1',
message : function(m){
//document.getElementById("stream").innerHTML=m.Humidity;
},
error : function (error) {
// Handle error here
console.log(JSON.stringify(error));
}
});
pubnub.history({
channel : 'Beehive_1',
callback : function(m){
document.getElementById("stream").innerHTML='';//JSON.stringify(m);
//chart1.series[0].setData(null);
var data = [];
for (i = 0; i < m[0].length; i++) {
var d = new Date(m[0][i].timetoken/10000);
data.push({
x: d,
y: parseFloat(m[0][i].message.Humidity)
});
/*document.getElementById("stream").innerHTML+=d;
document.getElementById("stream").innerHTML+=';';
document.getElementById("stream").innerHTML+=parseFloat(m[0][i].message.Humidity);
document.getElementById("stream").innerHTML+=',<br>';*/
}
//data.sort();//need to sort for zooming
...