Rails
Require it in your app/assets/javascripts/application.js.
//= require apexchartsOr, if you use webpacker, you can run:
$ yarn add apexchartsand then require it in your app/javascript/packs/application.js.
// AMD
window.ApexCharts = require("apexcharts") // expose to window
// or
// ES6
import ApexCharts from 'apexcharts'
window.ApexCharts = ApexChartsOr, if you use `importmaps', you can:
Download to local vendor directory (optional but recommended)
$ wget -O vendor/javascript/apexcharts.esm.js https://unpkg.com/apexcharts@latest/dist/apexcharts.esm.jsPin "apexcharts" in
config/importmap.rbto local esm file if you did No. 1:
pin "apexcharts", to: "apexcharts.esm.js"or, to CDN URL directly if you didn't do No. 1:
pin "apexcharts", to: "https://unpkg.com/apexcharts@latest/dist/apexcharts.esm.js"Import and assign to window in
app/javascript/application.js
import ApexCharts from "apexcharts"
window.ApexCharts = ApexChartsUse it with options
module: true
For example:
<% series = [{
name: "Desktops",
data: [10, 41, 35, 51, 49, 62, 69, 91, 148]
}]
options = {
module: true
}
%>
<%= line_chart(series, options) %>Last updated