3

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);               
});
Louys Patrice Bessette
  • 33,375
  • 6
  • 36
  • 64
2bb1s
  • 83
  • 4
  • Move the line : `var chart1 = new Highcharts.Chart(options);` inside the success callback of ajax. Ajax has an implied delay to get the information back. Since your ajax request is triggered onload (not on user action), it should solve your issue. – Louys Patrice Bessette Nov 12 '16 at 01:14

0 Answers0