Vova Rozhkov
Vova Rozhkov

Reputation: 1732

How to setup logarithmic axis for line chart in rails chartkick?

Is there way to setup log axis using chartkick and default chart.js library?

Upvotes: 1

Views: 362

Answers (2)

Jerome
Jerome

Reputation: 6189

Due to deprecation of methods in chart.js (effective from version 4.3) the syntax has changed.

[...]
legend: "bottom", library: { scales: { y: { type: 'logarithmic' } } }

legend is an attribute handle by chartkick and can be applied directly.

the yAxes and xAxes or rAxes calls are no longer used. The id is not a requirement. But the identification of the axis to which apply the option is. It now feels more natural, IMHO.

Upvotes: 1

Vova Rozhkov
Vova Rozhkov

Reputation: 1732

Yes, you can pass the axis options using 'library' option like this:

<%= line_chart data, {
    library: {
        legend: {
            position: 'bottom',
        },
        scales: {
            yAxes: [
                {
                    id: 'y-axis',
                      type: 'logarithmic'
                },]
        }
    }
} %>

For more options please consult with chart.js docs.

Upvotes: 3

Related Questions