Basically I have a object which defines some properties for a Highchart chart:
var options = {
chart: {
renderTo: 'container',
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: []
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function () {
return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y + '°C';
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: aCosts
}]
};
And I want to update this object from a file (ajax call) like so:
$.getJSON(
"handler.php",
function (oJSON) {
var sName,
sCost,
aRow;
for (sName in oJSON) {
aRow = [];
//categories = [];
if (oJSON.hasOwnProperty(sName)) {
aRow.push(sName);
categories.push(sName);
}
// Create the chart
var chart = new Highcharts.Chart(options);
}
}
);
The problem is, I can't pass the new value to options as it states that categories is not defined. I've tried using:
options.categories.push(sName)
options[categories].push(sName)
And none work.
How can I update the value of categories inside my options object?