DemoChart.vue
2.37 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
94
95
96
<template>
<div class="container">
<div id="main"></div>
<div id="main1" ref="elRef"></div>
</div>
</template>
<script lang="ts">
// https://vega.github.io/vega/usage/
import { defineComponent, onMounted, ref, unref } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';
import echarts from 'echarts';
export default defineComponent({
name: 'DemoChart',
setup() {
const elRef = ref<any>(null);
const { setOptions } = useECharts(elRef);
// onMounted(() => {
// const el = unref(elRef);
// if (!el || !unref(el)) return;
// const chart = echarts.init(el);
// window.addEventListener('resize', () => {
// chart!.resize();
// });
// // removeResizeFn = removeEvent;
// var option = {
// title: {
// text: 'ECharts entry example',
// },
// tooltip: {},
// legend: {
// data: ['Sales'],
// },
// xAxis: {
// data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks'],
// },
// yAxis: {},
// series: [
// {
// name: 'Sales',
// type: 'bar',
// data: [5, 20, 36, 10, 10, 20],
// },
// ],
// };
// chart && chart.setOption(option as any);
// });
onMounted(() => {
var myChart = echarts.init(elRef.value);
// specify chart configuration item and data
var option = {
title: {
text: 'ECharts entry example',
},
tooltip: {},
legend: {
data: ['Sales'],
},
xAxis: {
data: ['shirt', 'cardign', 'chiffon shirt', 'pants', 'heels', 'socks'],
},
yAxis: {},
series: [
{
name: 'Sales',
type: 'bar',
data: [5, 20, 36, 10, 10, 20],
},
],
};
setOptions(option);
// use configuration item and data specified to show chart
// myChart.setOption(option);
// window.addEventListener('resize', () => {
// myChart.resize();
// });
});
return { elRef };
},
});
</script>
<style>
.container {
width: 100%;
}
#main,
#main1 {
width: 40%;
height: 300px;
}
</style>