Giter Site home page Giter Site logo

Comments (9)

ankane avatar ankane commented on May 21, 2024 7

Hi all, Chartkick 5 is out and I'm still working on the docs, but the short version is:

For Importmaps, download the UMD version to vendor/javascript, pin it in config/importmap.rb, and use:

import "chartjs-plugin-annotation"

For esbuild, rollup.js, Webpack, or Webpacker, use:

import { Chart } from "chart.js"
import annotationPlugin from "chartjs-plugin-annotation"

Chart.register(annotationPlugin)

Then use the library option to apply it to charts:

<%= line_chart data, library: {plugins: {annotation: {annotations: {line1: {type: "line", yMin: 2, yMax: 2}}}}} %>

from chartkick.

itsgucci avatar itsgucci commented on May 21, 2024

I am trying to do this with importmap and am stumped at how to do it.

I downloaded chartjs-plugin-annotation.min.js into my app/javascript folder

my importmap.rb includes

pin "chartkick", to: "chartkick.js"
pin "Chart.bundle", to: "Chart.bundle.js"
pin "annotations", to: "chartjs-plugin-annotation.min.js"

and my app/javascript/application.js has

import "chartkick"
import "Chart.bundle"
import "annotations"
Chartkick.adapters[0].library.register("annotations");

but I am getting
Uncaught TypeError: Class extends value undefined is not a constructor or null

from chartkick.

itsyoshio avatar itsyoshio commented on May 21, 2024

I have the same problem @itsgucci

from chartkick.

saralhemnani avatar saralhemnani commented on May 21, 2024

Hey @itsyoshio did you find a solution?

from chartkick.

itsyoshio avatar itsyoshio commented on May 21, 2024

Hey @itsyoshio did you find a solution?

Sadly i did not

from chartkick.

ankane avatar ankane commented on May 21, 2024

Hey @alex-benoit, thanks for the suggestion, and sorry everyone for the delay.

This will be addressed in the Chartkick 5 release. Current status: #601 (comment)

from chartkick.

saralhemnani avatar saralhemnani commented on May 21, 2024

Thanks @ankane !

from chartkick.

swanson avatar swanson commented on May 21, 2024

Hi all, Chartkick 5 is out and I'm still working on the docs, but the short version is:

For Importmaps, download the UMD version to vendor/javascript, pin it in config/importmap.rb, and use:

import "chartjs-plugin-annotation"

For esbuild, rollup.js, Webpack, or Webpacker, use:

import { Chart } from "chart.js"
import annotationPlugin from "chartjs-plugin-annotation"

Chart.register(annotationPlugin)

Then use the library option to apply it to charts:

<%= line_chart data, library: {plugins: {annotation: {annotations: {line1: {type: "line", yMin: 2, yMax: 2}}}}} %>

Hey! Very helpful to get the plugins working. One note: you still need the chartkick/chart.js for this to work. I made the mistake of removing that line and it was tricky to debug

import 'chartkick/chart.js'
import { Chart } from 'chart.js'
import annotationPlugin from 'chartjs-plugin-annotation'
Chart.register(annotationPlugin)

from chartkick.

alex-benoit avatar alex-benoit commented on May 21, 2024

❤️

from chartkick.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.