Reputation: 435
I am trying to implement Higcharts in my project,
What I have is a function in which I am defining var options
of Highcharts so that I can use that option
variable in the Highchart.
but when I am using that Variable in the Highcharts its displaying the Following error :
Uncaught ReferenceError: options is not defined
Here's How I tried my code :
function data(response){
var options = {
// Some Code that goes in option
}
}
and here's how I anm Calling it ;
data(response);
Highcharts.Chart.update(options);
I already mentioned what my error is. Please correct me where I am wrong. Any help is really Appreciated
Upvotes: 1
Views: 3593
Reputation: 39099
You can also return options from the function:
var chart = Highcharts.chart('container', {
series: [{
data: [1,2,3]
}]
});
function data(response) {
var options = {
series: [{ data: [10, 20, 30] }]
}
return options;
}
setTimeout(function(){
chart.update(data());
}, 1000);
Live demo: http://jsfiddle.net/BlackLabel/fug2x3v4/
API Reference: https://api.highcharts.com/class-reference/Highcharts.Chart#update
Upvotes: 2
Reputation: 1502
You have declared the variable inside the function but using it outside the function where you will always get variable undefined
error. You should create a global variable or in the same scope where you are using it.
var options = {};
function data(response){
options = {
// Some Code that goes in option
}
}
data(response);
Highcharts.Chart.update(options);
Upvotes: 0