Chartjs-Rails dual axis using Chartkick and chart js

2👍

You need to make sure to pass the scales in the correct format. See this example of using Axis IDs in the docs.
I.e. scales needs to contain a yAxes field with an array of the axis objects and each axis object has an id field that matches one of the IDs from your datasets.

So, you should change your code to something like this:

<%= line_chart @consultations, legend: true, library: {
    legend: { position: 'top' },
    scales: {
        yAxes: [
            {
                id: 'y',
                type: 'linear',
                display: true,
                position: 'left',
            },
            {
                id: 'y1',
                type: 'linear',
                display: true,
                position: 'right',
            }
        ]
    }
}, id: 'consult-chart', adapter: 'chartjs' %>

Leave a comment