liveLineChart.vue
1.83 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
<div v-if="chartData != null">
<highcharts :options="options"
:callback="onChartLoaded"
:class="chartClass"
:style="borderStyle"
/>
</div>
</template>
<script>
import { Chart } from 'highcharts-vue';
export default {
name: 'liveLineChart',
components: {
highcharts: Chart,
},
props: {
chartData: {
type: Array,
default: null,
},
chartSettings: {
type: Object,
default: null,
},
chartClass: {
type: String,
default: null,
},
bordered: {
type: Boolean,
default: null,
},
},
data() {
return {
chart: null,
options: {},
borderStyle: {},
};
},
watch: {
chartSettings: {
deep: true,
handler(val) {
if (val == null) return;
this.setCustomChartSetting(val);
if (this.chart == null) return;
this.chart.redraw();
this.chart.setSize(null);
},
},
},
created() {
this.options.series = this.chartData;
this.setCustomChartSetting(this.chartSettings);
if (this.bordered) {
this.borderStyle = {
border: '2px solid #dde2ec',
};
}
},
methods: {
onChartLoaded(chart) {
if (this.chart == null) { this.chart = chart; }
this.chart.zoomOut(false);
this.chart.redraw();
this.chart.setSize(null);
},
/**
* Label Formatter로 Html로 레이블 설정 가능
* 자세한 설정은 https://api.highcharts.com/highcharts/plotOptions
* @param settings
*/
setCustomChartSetting(settings) {
this.options.chart = {
type: 'line',
};
if (settings == null) return;
this.options = { ...settings, series: this.chartData };
this.options.chart.type = 'line';
},
},
};
</script>
<style scoped>
</style>