【问题标题】:How to add a second xAxis to Highcharts Stockchart如何将第二个 xAxis 添加到 Highcharts Stockchart
【发布时间】:2014-04-22 11:46:15
【问题描述】:

我有一个现有的 Highstock 图表,其中包含一个 xAxis 和一个 yAxis。我的目标是在按下按钮时添加第二个带有数据的 xAxis。 我的代码如下所示:

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]
});

}

添加系列数据时,找不到 xAxis 对象。我在 id 以及数组长度“xAxis:1”的帮助下尝试了绑定。 甚至可以在 Highstock 图表上应用 addAxis 方法,还是只对 Highcharts 应用?

非常感谢任何帮助!

【问题讨论】:

    标签: javascript highcharts axis highstock


    【解决方案1】:

    它适用于 3.0.10,请参阅: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]
        });
    });
    

    【讨论】:

    • 非常感谢 Pawel,这就是问题所在。更新到 3.0.10 版本后,它工作正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-09-30
    相关资源
    最近更新 更多