user2761225
user2761225

Reputation: 5

Highcharts 2nd yaxis not scaling

i can see 2 y axes but how can i scale the second? Where i have to put code? I get data from database using json.php which i don't include because i am sure i get results...as i said i can see lines........

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

}

Upvotes: 0

Views: 216

Answers (1)

Kacper Madej
Kacper Madej

Reputation: 7886

Have you assigned any series to second y axis? That might be the problem.

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/

in your code you should add line in

$.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);          
    },
});

Upvotes: 1

Related Questions