scatterChart.vue
4.34 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
<div>
<basic ref="basic" :chartId="chartId" :chartData="chartData"></basic>
</div>
</template>
<script>
import mixin from './mixin';
import _ from 'underscore';
export default {
mixins: [mixin],
data() {
return {
}
},
methods: {
/**
* 预处理option参数
* */
preChartData(cdata) {
return cdata;
},
/**
* 处理option参数
* */
dealChartData(optionFormat) {
// 特殊配置项
let { kpiName, grid, _color } = optionFormat.otherConf;
//optionFormat.xAxis.name = this.$t("table.date");
optionFormat.xAxis.type = 'value';
optionFormat.xAxis.splitLine = {
show:false
}
optionFormat.yAxis.name = "女\n性\n占\n比";
optionFormat.yAxis.nameLocation = 'middle';
optionFormat.yAxis.nameGap = 25;
optionFormat.yAxis.splitNumber = 2;
optionFormat.yAxis.offset = 0;
optionFormat.yAxis.nameRotate = 0;
optionFormat.yAxis.axisLine = {
show:true,
lineStyle:{color:'#ccc'}
}
optionFormat.yAxis.axisTick = {
show:false
}
optionFormat.yAxis.axisLabel = {
inside:true,
show:true,
showMaxLabel:true
}
optionFormat.grid = grid || { top: 40, right: 20, left: 40,bottom:20 };
optionFormat.legend.top = 26;
optionFormat.legend.fontSize = 14;
let tooltipData = [],
dataNumArr = [],
maxNum = null,
minNum = null,
maxSize = 100,
minSize = 30,
symbolsizeArr = [],
sessionLocalWeather = "",
legendName = "",
legendData = [],
newSeries = [];
optionFormat.series.forEach((item, index) => {
tooltipData[legendName] = item.data;
item.name = legendName;
item.type = "scatter";
item.itemStyle = {
normal: {
// color: _color[index],
// borderColor: _color[index],
borderWidth: 2,
opacity: 0.6
},
};
symbolsizeArr[index] = [];
item.data.forEach((dataItem, dataIndex) => {
if (dataItem) {
symbolsizeArr[index][dataIndex] = dataItem.value1;
dataNumArr.push(dataItem.value1);
} else {
symbolsizeArr[index][dataIndex] = 0;
}
});
});
newSeries = Object.assign([], optionFormat.series);
maxNum = _.max(optionFormat.xAxis.data);
minNum = _.min(optionFormat.xAxis.data);
optionFormat.xAxis.min = minNum;
optionFormat.xAxis.max = maxNum;
let option = Object.assign({}, optionFormat); // coverTemp
option.series = newSeries.map((item, index) => {
item.label = {
show: true,
color:'#444',
//fontWeight:'bold',
//position: 'inside',
formatter(data){
return data.data[3]
}
};
let arr = _.map(item.data,(it=>it[2]));
let min = _.min(arr);
let max = _.max(arr);
item.symbolSize = (data, param) => {
let _size = minSize + (maxSize-minSize)*(data[2]-min)/(max-min);
return parseInt(_size);
};
let colorArr = _.map(this.getRandomColors(item.data.length),(color,idx)=>{
return {
value: item.data[idx][2],
label: item.data[idx][3],
color:color
};
});
option.visualMap = {
show:false,
type: 'piecewise',
top: 'middle',
splitNumber: item.data.length,
min: min,
dimension: 2,
max: max,
pieces:colorArr
}
return item;
});
option.legend.data = legendData;
option.legend.show = false;
option.tooltip.formatter = params => {
let data = params.data;
let htmls = '';
htmls+=`<div>
<p>${data[3]}</p>
<p>年龄中位数:<span style="color:#5093fa">${data[0]}</span>岁</p>
<p>女性占比:<span style="color:#5093fa">${(data[1]*100).toFixed(0)}</span>%</p>
<p>到访人数:<span style="color:#5093fa">${this.toThousands(data[2])}</span>人</p>
</div>`
return htmls;
};
return option;
}
},
created() {
}
}
</script>
<style scoped>
.chart {
position: relative;
height: 500px;
}
</style>