Skip to content

Instantly share code, notes, and snippets.

@narath
Last active February 2, 2024 02:14
Show Gist options
  • Save narath/307b04ef623a7dd98793042bdf5f7469 to your computer and use it in GitHub Desktop.
Save narath/307b04ef623a7dd98793042bdf5f7469 to your computer and use it in GitHub Desktop.
How to use the annotations plugin with Rails 7 using Webpacker and Chartkick
yarn add chartjs-plugin-annotation

Then edit app/javascript/application.js

import "chartkick/chart.js"

# Add these lines
import annotationPlugin from 'chartjs-plugin-annotation';
Chartkick.adapters[0].library.register(annotationPlugin);

See this pull request for more details

You can then add annotations using the following example format:

<%= line_chart data, library: {plugins: {annotation: {annotations: {line1: {type: "line", yMin: 2, yMax: 2}}}}} %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment