I have the following code: http://jsfiddle.net/maniator/vTjW8/
var createChartTemplate = function() {
return {
chart: new Highcharts.StockChart({
chart: {
renderTo: 'container'
},
series: []
}),
addSeries: function(name) {
this.chart.addSeries({
name: name,
data: [],
id: Math.floor(Math.random()*1000)
});
},
addPoint: function(data, series) {
var seriesIndex = this.seriesExists(series);
if (!(seriesIndex === false)) {
this.chart.series[seriesIndex].addPoint(data, false);
}
this.chart.redraw();
},
seriesExists: function(series) {
var seriesIndex = false;
$.each(this.chart.series, function(index, item) {
if ($.trim(item.name) == $.trim(series)) {
seriesIndex = index;
return false;
}
});
return seriesIndex;
}
}
}
$(function() {
var data = usdeur.splice(0, 700);
var chart = createChartTemplate();
chart.addSeries("New Series");
for (var i = 0; i < data.length; i++) {
chart.addPoint(data[i], "New Series");
}
});
It has the following error in the console:
Uncaught TypeError: Cannot read property 'options' of undefined
This code works fine if it is a normal highchart, but for some reason it does not work with a HighStock chart.
How can I make it so that it works with the chart type that I need?
Update:
I figures out a sort of way around getting the 1st series dynamically, but then when I try to add a second series it has an error of:
Uncaught TypeError: Cannot read property 'stacks' of undefined
Fiddle: http://jsfiddle.net/maniator/V5WAJ/