-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathVueC3.vue
63 lines (54 loc) · 1.2 KB
/
VueC3.vue
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
59
60
61
62
63
<template>
<div class="vuec3-chart"></div>
</template>
<script>
import c3 from 'c3'
import * as events from './events'
export default {
name: 'vuec3',
// TODO: support for options prop
props: {
handler: {
required: true,
type: Object
}
},
data: function () {
return {
$chart: null
}
},
methods: {
destroyChart: function () {
if (this.$chart) {
this.$chart = this.$chart.destroy()
}
},
initChart: function (options) {
if (this.$chart) {
this.destroyChart();
}
if (!options) {
options = {};
}
options.bindto = this.$el;
this.$chart = c3.generate(options);
},
dispatchChart: function (cb) {
if (cb && this.$chart) {
cb.call(null, this.$chart);
}
}
},
mounted: function () {
if (this.handler) {
this.handler.$on(events.INIT, this.initChart);
this.handler.$on(events.DESTROY, this.destroyChart);
this.handler.$on(events.DISPATCH, this.dispatchChart);
}
},
beforeDestroy: function () {
this.destroyChart()
}
}
</script>