Fusher wrote:Can You share with Your example?
Sorry for the delay.
Here is the example. I have taken your code and made the following changes:
1) chart = new Highcharts.Chart
( instead of chart = new Highcharts.StockChart )
2) added
- Code: Select all
scrollbar: {
enabled: true
},
xAxis: {
min: 1255475600000
},
to the chart config object
3) modified the click event handler
When you run this code and click on the button you get the error.
- Code: Select all
var seriesOptions = [], seriesOptions2 = [],
yAxisOptions = [],
seriesCounter = 0,
names = ['MSFT'],
names2 = ['GOOG'],
colors = Highcharts.getOptions().colors;
$.each(names, function(i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
seriesOptions[i] = {
name: name,
data: data
};
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
seriesCounter++;
if (seriesCounter == names.length) {
createChart();
}
});
});
$.each(names2, function(i, name) {
$.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename='+ name.toLowerCase() +'-c.json&callback=?', function(data) {
seriesOptions2[i] = {
name: name,
data: data
};
console.log(seriesOptions2);
// As we're loading the data asynchronously, we don't know what order it will arrive. So
// we keep a counter and create the chart when all the data is loaded.
// seriesCounter++;
// if (seriesCounter == names.length) {
// createChart();
// }
});
});
$('#btn').click(function() {
//chart.series[0].setData(seriesOptions2[0].data,true);
chart.series[0].setData(seriesOptions2[0].data,true);
chart.series[0].chart.addSeries({data:seriesOptions2[0].data}, false);
chart.series[0].remove();
});
// create the chart when all data is loaded
function createChart() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
rangeSelector: {
selected: 4
},
scrollbar: {
enabled: true
},
xAxis: {
min: 1255475600000
},
yAxis: {
labels: {
formatter: function() {
return (this.value > 0 ? '+' : '') + this.value + '%';
}
},
plotLines: [{
value: 0,
width: 2,
color: 'silver'
}]
},
plotOptions: {
series: {
compare: 'percent'
}
},
tooltip: {
pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
yDecimals: 2
},
series: seriesOptions
});
}