I can't seem to add new plotLines when the code[options.xAxis.plotLines.push({value: 100,color: 'red',width:1});] is in a function. But when is outside of a function everything works fine. I have checked that the variables are integers after doing equations with the numbers and sent the data to console.log I am trying to add new plotLines based on some database numbers.
$(function () {
Highcharts.setOptions({
chart: {
backgroundColor: null
}
});
var options = {
xAxis: {
plotLines:[
]
},
chart: {
renderTo: 'container'
},
series: [{
data: [<?php echo join($data, ',') ?>],
pointStart: 0,
//pointInterval
}]
}
function add(r) {
options.xAxis.plotLines.push({value: r,color: 'red',width:1});//will not create object
console.log(r);
}
options.xAxis.plotLines.push({value: 132,color: 'red',width:1}); //will create object
$.ajax({
url: '../includes/api.php', data: "", dataType: 'json', success:
function(rows)
{
for (var i in rows){
var row = rows[i];
console.log(this, row);
add(row)
options.xAxis.plotLines.push({value: row,color: 'red',width:1}); //will not create object
}
}
});
var chart1 = new Highcharts.Chart(options);
});