Created
July 12, 2013 13:27
-
-
Save robinvanb/5984453 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chart = new Highcharts.Chart({ | |
chart : { | |
renderTo : ‘chart’, | |
type : ‘column’ | |
}, | |
title : { | |
text : ‘Word count’ | |
}, | |
xAxis : { | |
title : { | |
text : null | |
} | |
}, | |
yAxis : { | |
min : 0, | |
title : { | |
text : ‘Count’, | |
align : ‘high’ | |
}, | |
labels : { | |
overflow : ‘justify’ | |
} | |
}, | |
plotOptions : { | |
bar : { | |
dataLabels : { | |
enabled : true | |
} | |
} | |
}, | |
legend : { | |
layout : ‘vertical’, | |
align : ‘right’, | |
verticalAlign : ‘top’, | |
floating : true, | |
borderWidth : 1, | |
backgroundColor : ‘#FFFFFF’, | |
shadow : true | |
}, | |
credits : { | |
enabled : false | |
}, | |
series : [ | |
] | |
}); | |
Lastly, whenever data is received through WebSockets the data is read (it’s JSON) and added to the graph through the following function: | |
function redraw(index, data) { | |
if (index < 0) { | |
var series = { | |
id : data.x, | |
name : data.x, | |
data : [data.y] | |
}; | |
chart.addSeries(series); | |
} else { | |
for (var i = 0; i < chart.series.length; i++) { | |
if (chart.series[i].name == data.x) { | |
chart.series[i].setData([data.y]); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment