You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
752 B
25 lines
752 B
import '../plugin/apexchart.js'
|
|
|
|
export default function AlpineChart(Alpine) {
|
|
Alpine.directive('chart', function (el, { expression }, { evaluate, cleanup }) {
|
|
let config = evaluate(expression);
|
|
|
|
const chart = new window.ApexCharts(el, config);
|
|
chart.render();
|
|
|
|
const event = function(event) {
|
|
const newData = event.detail
|
|
chart.updateSeries(newData.series, true, true);
|
|
chart.updateOptions(newData.options, true, true);
|
|
}
|
|
|
|
name = el.getAttribute('id');
|
|
|
|
window.addEventListener(`chart-${name}-update`, event)
|
|
|
|
cleanup(() => {
|
|
chart.destroy();
|
|
window.removeEventListener(`chart-${name}-update`, event)
|
|
});
|
|
})
|
|
}
|
|
|