Highcharts 2nd yaxis没有缩放

时间:2014-12-05 10:46:37

标签: highcharts

我可以看到2个y轴,但我如何缩放第二个?我必须把代码放在哪里?我使用json.php从数据库获取数据,我没有包括因为我确定我得到了结果...因为我说我可以看到行........

function InitHighChart()
{
$("#chart").html("Wait, Loading graph...");

var options = {
    chart: {
        renderTo: 'chart',
        borderColor: '#a1a1a1',
        borderWidth: 2,
        borderRadius: 13,
        alignTicks: false,
        height: 550
    },
    credits: {
        enabled: false
    },
    title: {
        text: 'Ενεργός Ισχύς / Τάση',
        x: -20
    },
    xAxis: {
        categories: [{}],
        labels: {
            step: 15,
            rotation: -75
        }
    },

     yAxis: [{ // Primary yAxis
        labels: {
            format: '{value} MWatt',


        },
        title: {
            text: 'Ενεργός Ισχύς',

        }

    }, { // Secondary yAxis
        title: {
            text: 'Τάση',

        },
        labels: {
            format: '{value} V',

        },
        opposite: true
    }],


    tooltip: {
        formatter: function() {
            var s = '<b>'+ this.x +'</b>';

            $.each(this.points, function(i, point) {
                s += '<br/>'+point.series.name+': '+point.y;
            });

            return s;
        },
        shared: true
    },
    series: [{},{}]
};

$.ajax({
    url: "json.php",
    data: 'show=impression',
    type:'post',
    dataType: "json",
    success: function(data){

        options.xAxis.categories = data.datetime;
        options.series[0].name = '...';
        options.series[0].data = data.ActiveData;
        options.series[1].name = '...';
        options.series[1].data = data.VoltageData;

        var chart = new Highcharts.Chart(options);          
    },
});

}

1 个答案:

答案 0 :(得分:1)

您是否已将任何系列分配到第二个y轴?这可能是问题所在。

API:http://api.highcharts.com/highcharts#series.yAxis

series: [{
        data: [1, 2, 3, 4, 5, 3, 5]
    }, {
        data: [3, 3, 5, 4, 6, 6, 3, 3, 4, 6],
        yAxis: 1
}]

jsFiddle:http://jsfiddle.net/boog4dpe/

在你的代码中你应该在

中添加一行
$.ajax({
    url: "json.php",
    data: 'show=impression',
    type:'post',
    dataType: "json",
    success: function(data){

        options.xAxis.categories = data.datetime;
        options.series[0].name = '...';
        options.series[0].data = data.ActiveData;
        options.series[1].name = '...';
        options.series[1].data = data.VoltageData;

        options.series[1].yAxis = 1; //added line

        var chart = new Highcharts.Chart(options);          
    },
});