Skip to content

Instantly share code, notes, and snippets.

@robinvanb
Created July 12, 2013 13:27
Show Gist options
  • Save robinvanb/5984453 to your computer and use it in GitHub Desktop.
Save robinvanb/5984453 to your computer and use it in GitHub Desktop.
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