Closed bxkx closed 6 months ago
Hi @bxkx, I tested both plugins as part of #597 and didn't come across any issues.
Make sure you're using the UMD versions. Also, the datalabels plugin needs to be registered.
Chart.register(ChartDataLabels)
// and optionally hide by default
Chart.defaults.set("plugins.datalabels", {display: false})
I'm not sure about the issue with zoom functionality, but seems unlikely it's something with Chartkick (but happy to revisit if there's more evidence).
Thank you, it's all working now! I tried to register it in various ways, I even had that exact line in the file, but only in conjunction with the "import from" stuff that made it not work. I didn't know nor tried I could just put that single line since I thought this was meant to be together with the other lines. For the panning to work I just needed to add hammer.js - I guess webpack/jsbundling added that automatically, so I wasn't aware. I feel a bit dumb, but I learned :D
I noticed the chartjs-plugin-zoom and chartjs-plugin-datalabels don't work correctly and not at all, respectively, with latest Rails and the Importmaps it ships with. Both plugins worked just fine with jsbundling/webpack I used previously. As per the guide I downloaded the .js file from their respective repos and added them to vendor/javascript and added the following to
importmap.rb
application.js
Chart in the .html.erb
The zooming works. I can drag the mouse across the chart and it zooms into the area. Holding ctrl and dragging does not work. It does seem to register that ctrl is held because it prevents the zoom-drag function as it should. The datalabels just don't show up at all. There are no errors in the console.
Seems like bug/incompatibility. Or am I missing something glaring?
HTML generated by Chartkick