Question

I have an existing Highstock chart with one xAxis and one yAxis. My goal is to add a second xAxis with data on the press of a button. My code looks like this:

showDrehzahl: function() {

console.log('add axis function called');

var chart = $('#mycontainer').highcharts();

//Second xAxis
chart.addAxis({ 
    id: 'drehzahl',
    title: {
        text: 'Drehzahl'
    },
    lineWidth: 2,
    lineColor: '#000000',
    opposite: true
},true);

console.log('add series');

console.log(chart);

chart.addSeries({
    name: 'Drehzahl',
    type: 'spline',
    color: '#000000',
    xAxis: 'drehzahl',
    data: [49.9, 9, 10.4, 12.2, 14.0, 16.0, 13.6, 14.5, 6.4, 14.1, 9.6, 5.4]
});

}

When adding the series data, the xAxis object can not be found. I tried the binding with the help of the id as well as with the array length "xAxis: 1". Is it even possible to apply the addAxis method on Highstock charts, or only to Highcharts?

Any help is highly appreciated!

Was it helpful?

Solution

It works in 3.0.10, see: http://jsfiddle.net/3bQne/1020/

var chart = new Highcharts.StockChart({
    chart: {
        renderTo: 'container'
    },
    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0]
    }]
});

$("#b").click(function () {
    chart.addAxis({
        id: 'drehzahl',
        lineWidth: 2,
        lineColor: '#000000',
        opposite: true
    }, true);

    chart.addSeries({
        type: 'spline',
        color: '#000000',
        xAxis: 'drehzahl',
        data: [49.9, 9, 10.4, 12.2, 14.0, 16.0, 13.6, 14.5, 6.4, 14.1, 9.6, 5.4]
    });
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top