tiaoxing.vue
2.39 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
<template>
<div style="margin-bottom:20px;border: 1px solid #dddfe5;padding:20px;">
<div style="font-size:16px;margin-bottom:20px;">{{ title }}</div>
<div style="display: flex;">
<div style="width: 45%;display: flex;justify-content: space-evenly;">
<div ref="chart" style="width: 300px; height: 300px;"></div>
</div>
<div style="width: 55%;">
<el-table :data="tableData" :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}" >
<el-table-column prop="label" label="序号" width="180"></el-table-column>
<el-table-column prop="value" label="选项" width="200"></el-table-column>
<el-table-column prop="label" label="选择次数" width="180"></el-table-column>
<el-table-column prop="label" label="百分比" width="180"></el-table-column>
</el-table>
</div>
</div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import { Table, TableColumn } from 'element-ui';
export default {
name: 'DynamicChartTable',
components: {
'el-table': Table,
'el-table-column': TableColumn
},
props: {
title: {
type: String,
required: true
},
tableData: {
type: Array,
required: true
}
},
mounted() {
this.initChart();
},
methods: {
initChart() {
console.log(this.tableData)
var labels = this.tableData.map(item => item.label)
var values = this.tableData.map(item => item.value)
const option = {
legend: {},
tooltip: {},
xAxis: {
type: 'category',
data: labels
},
yAxis: {
type: 'value',
},
grid: {
left: '1%',
right: '1%',
top: '5%',
bottom: '6%',
containLabel: true
},
series: [{
type: 'bar',
data: values,
color: '#3f9b6a'
}]
}
const chartDom = this.$refs.chart;
const myChart = echarts.init(chartDom);
option && myChart.setOption(option);
}
},
beforeDestroy() {
if (this.$refs.chart) {
const myChart = echarts.getInstanceByDom(this.$refs.chart);
if (myChart) {
window.removeEventListener('resize', myChart.resize);
myChart.dispose();
}
}
}
};
</script>
<style scoped>
/* 添加一些基本样式 */
</style>