Skip to content

Commit 2775671

Browse files
committed
add a check to see if props.chart exists; ref PR #105
1 parent d434a48 commit 2775671

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/vue3-apexcharts.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
watch,
1010
onBeforeMount,
1111
nextTick,
12-
toRefs
12+
toRefs,
1313
} from "vue";
1414
import ApexCharts from "apexcharts";
1515

@@ -33,28 +33,28 @@ const events = [
3333
"beforeResetZoom",
3434
"zoomed",
3535
"scrolled",
36-
"brushScrolled"
36+
"brushScrolled",
3737
];
3838

3939
const vueApexcharts = defineComponent({
4040
name: "apexchart",
4141
props: {
4242
options: {
43-
type: Object
43+
type: Object,
4444
},
4545
type: {
46-
type: String
46+
type: String,
4747
},
4848
series: {
4949
type: Array,
50-
required: true
50+
required: true,
5151
},
5252
width: {
53-
default: "100%"
53+
default: "100%",
5454
},
5555
height: {
56-
default: "auto"
57-
}
56+
default: "auto",
57+
},
5858
},
5959

6060
// events emitted by this component
@@ -64,14 +64,14 @@ const vueApexcharts = defineComponent({
6464
const __el = ref(null);
6565
const chart = ref(null);
6666

67-
const isObject = item => {
67+
const isObject = (item) => {
6868
return item && typeof item === "object" && !Array.isArray(item) && item != null;
6969
};
7070

7171
const extend = (target, source) => {
7272
if (typeof Object.assign !== "function") {
73-
(function() {
74-
Object.assign = function(target) {
73+
(function () {
74+
Object.assign = function (target) {
7575
// We must check against these specific cases.
7676
if (target === undefined || target === null) {
7777
throw new TypeError("Cannot convert undefined or null to object");
@@ -95,18 +95,18 @@ const vueApexcharts = defineComponent({
9595

9696
let output = Object.assign({}, target);
9797
if (isObject(target) && isObject(source)) {
98-
Object.keys(source).forEach(key => {
98+
Object.keys(source).forEach((key) => {
9999
if (isObject(source[key])) {
100100
if (!(key in target)) {
101101
Object.assign(output, {
102-
[key]: source[key]
102+
[key]: source[key],
103103
});
104104
} else {
105105
output[key] = extend(target[key], source[key]);
106106
}
107107
} else {
108108
Object.assign(output, {
109-
[key]: source[key]
109+
[key]: source[key],
110110
});
111111
}
112112
});
@@ -116,26 +116,26 @@ const vueApexcharts = defineComponent({
116116

117117
const init = async () => {
118118
await nextTick();
119-
119+
120120
if (chart.value) {
121-
return;
121+
return;
122122
}
123123

124124
const newOptions = {
125125
chart: {
126126
type: props.type || props.options.chart.type || "line",
127127
height: props.height,
128128
width: props.width,
129-
events: {}
129+
events: {},
130130
},
131-
series: props.series
131+
series: props.series,
132132
};
133133

134134
// emit events to the parent component
135135
// to allow for two-way data binding, while
136136
// also allowing chart options to define callbacks
137-
const optionsEvents = props.options.chart.events;
138-
events.forEach(event => {
137+
const optionsEvents = props.options.chart?.events;
138+
events.forEach((event) => {
139139
let callback = (...args) => emit(event, ...args); // args => chartContext, options
140140
newOptions.chart.events[event] = (...args) => {
141141
callback(...args);
@@ -167,15 +167,15 @@ const vueApexcharts = defineComponent({
167167
return chart.value.updateOptions(newOptions, redrawPaths, animate, updateSyncedCharts);
168168
};
169169

170-
const toggleSeries = seriesName => {
170+
const toggleSeries = (seriesName) => {
171171
return chart.value.toggleSeries(seriesName);
172172
};
173173

174-
const showSeries = seriesName => {
174+
const showSeries = (seriesName) => {
175175
chart.value.showSeries(seriesName);
176176
};
177177

178-
const hideSeries = seriesName => {
178+
const hideSeries = (seriesName) => {
179179
chart.value.hideSeries(seriesName);
180180
};
181181

@@ -191,19 +191,19 @@ const vueApexcharts = defineComponent({
191191
chart.value.toggleDataPointSelection(seriesIndex, dataPointIndex);
192192
};
193193

194-
const appendData = newData => {
194+
const appendData = (newData) => {
195195
return chart.value.appendData(newData);
196196
};
197197

198198
const zoomX = (start, end) => {
199199
return chart.value.zoomX(start, end);
200200
};
201201

202-
const dataURI = options => {
202+
const dataURI = (options) => {
203203
return chart.value.dataURI(options);
204204
};
205205

206-
const setLocale = localeName => {
206+
const setLocale = (localeName) => {
207207
return chart.value.setLocale(localeName);
208208
};
209209

@@ -297,15 +297,15 @@ const vueApexcharts = defineComponent({
297297
removeAnnotation,
298298
clearAnnotations,
299299
setLocale,
300-
dataURI
300+
dataURI,
301301
};
302302
},
303303

304304
render() {
305305
return h("div", {
306-
class: "vue-apexcharts"
306+
class: "vue-apexcharts",
307307
});
308-
}
308+
},
309309
});
310310

311311
export default vueApexcharts;

0 commit comments

Comments
 (0)