score:3

Accepted answer

As the doc of Highcharts says, "The point options. If options is a single number, a point with that y value is appended to the series.If it is an array, it will be interpreted as x and y values respectively." So just give an array as the parameter of addPoint().

To remove a point, use removePoint.

Here is the example which add the point in the position "i", and remove the point in the position "i":

$(function () {
    $('#container').highcharts({

        series: [{
            data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }]

    });


    // the button action
    var i = 0;
    $('#button').click(function () {
        var chart = $('#container').highcharts();
        chart.series[0].addPoint([i, 50 * (i % 3)]);
        i += 1;
    });

    $('#removebutton').click(function () {
        var chart = $('#container').highcharts();
        chart.series[0].removePoint(i);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>
<button id="button" class="autocompare">Add point</button>
<button id="removebutton" class="autocompare">remove point</button>

score:2

You need to specify both the x and y coordinates, otherwise it is going to assume that the x coordinate is the next data point on the x axis. Try this:

$(function () {
$('#container').highcharts({

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]

});


// the button action
var i = 0;
$('#button').click(function () {
    var chart = $('#container').highcharts();
    chart.series[0].addPoint({
    x: 2*i, // or some other value
    y: 50 * (i % 3)
});
    i += 1;
});

});


Related Query

More Query from same tag