forked from leandrocfe/filament-apex-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apexcharts.js
58 lines (47 loc) · 1.48 KB
/
apexcharts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import ApexCharts from 'apexcharts'
var merge = require('lodash.merge');
export default function apexcharts({
options,
chartId,
theme,
extraJsOptions
}) {
return {
chart: null,
options,
chartId,
theme,
extraJsOptions,
init: function () {
this.$wire.$on('updateOptions', ({ options }) => {
options = merge(options, this.extraJsOptions)
this.updateChart(options)
})
Alpine.effect(() => {
const theme = Alpine.store('theme')
this.$nextTick(() => {
if (this.chart === null) {
this.initChart()
} else {
this.updateChart({
theme: { mode: theme },
chart: {
background: 'inherit'
}
})
}
})
})
},
initChart: function () {
this.options.theme = { mode: this.theme }
this.options.chart.background = 'inherit'
this.options = merge(this.options, this.extraJsOptions)
this.chart = new ApexCharts(document.querySelector(this.chartId), this.options)
this.chart.render()
},
updateChart: function (options) {
this.chart.updateOptions(options, false, true, true)
},
}
}