[SOLVED] How to pass options for ChartJS plugin using Chartkick in Ruby on Rails

Correct syntax for that chartjs plugins using chartkick in Rails

me@jaykilleen.com wrote this about 2 years ago and it was last updated about 2 years ago.


← Back to the Posts

I am using chartkick with chartjs on Ruby on Rails and also the chartjs-plugin-datalabels plugin.

After running into difficulty and reading the response on this Chartkick Github issue I decided to write up a solution if I ever managed to figure out how to get datalabels to work.

Here is my code that works. Notice the syntax/structure of the library: {} part.

<%= line_chart data, 
  height: "128px", 
  loading: "Loading...", 
  curve: false, 
  empty: "No data returned.", 
  library: {}, 
  dataset: {
    pointStyle: 'circle',
    datalabels: {
    color: '#003d68',
    font: {
      weight: '800'
    },
    anchor: 'center',
    clamp: true,
    align: 'top',
    display: 'auto'
    }
  }
%>