Search code examples
highcharts

Highcharts - Combine y axes


Is there a way to combine different y axes into one?

I have 23 data sets that I want to display on the same line graph and I want it to only have one y axis, despite the fact that the different lines' values highly differ (for example, points in one line can fluctuate around 50 000 and in another line around 5 or 6).

What I am looking for is this: combinedyaxes


Solution

  • You can mock multiple y axes to be shown as one. One main axis should have line and ticks, the other should not - you can set that with tickWidth, tickLength and lineWidth options (for each axis separately).

    Then you need to set vertical position of the axes by setting their offset to 0. You also need adjust their min, max and tickPositions to fit the data.

    Example of the axes config:

    yAxis: [{ // Primary yAxis
        min: 4.5,
        max: 27.5,
        tickPositions: [7, 25],
        startOnTick: false,
        endOnTick: false,
        gridLineWidth: 0,
        offset: 0,
        labels: {
            format: '{value}°C',
            style: {
                color: Highcharts.getOptions().colors[2]
            }
        },
        title: {
            text: null
        },
    
    }, { // Secondary yAxis
        gridLineWidth: 0,
        offset: 0,
        title: {
            text: null
        },
        labels: {
            format: '{value} mm',
            style: {
                color: Highcharts.getOptions().colors[0]
            }
        },
        lineWidth: 1,
        tickLength: 10,
        tickWidth: 1,
        tickPositions: [49.9, 220]
    }, { // Tertiary yAxis
        gridLineWidth: 0,
        endOnTick: false,
        startOnTick: false,
        min: 1009,
        max: 1018.5,
        tickPositions: [1009.5, 1018],
        offset: 0,
        title: {
            text: null
        },
        labels: {
            format: '{value} mb',
            style: {
                color: Highcharts.getOptions().colors[1]
            }
        }
    }],
    

    example: http://jsfiddle.net/w7z1p8qy/

    combine multipel y axies