heatChart.vue
6.11 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<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 yAxisData = optionFormat.series.map((item) => item.name);
let seriesData = [],
yIndex = null,
maxArr = [],
onedimen = [],
maxNum = null,
legendShow = false,
{
hideVisualMap = false,
visualColor,
dateSort = false,//是否按周进行排序
perUnit = painter.$t('format.perTime'),
hidexAxis = false,
_grid,
_yAxis,
isObjValue = false,
} = optionFormat.otherConf;
/*********格式化自定义的 y 轴*****************/
if(dateSort){
yAxisData = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"];
if (window.localStorage.getItem("lang") == "en_US") {
yAxisData = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
}
}
/******************************************/
optionFormat.series.forEach((item, index) => {
yIndex = yAxisData.indexOf(item.name);
if (typeof item.data[0] == "number") {
maxArr.push(item.data);
} else {
maxArr.push(_.pluck(item.data, "value"));
}
item.data.forEach((dataItem, dataIndex) => {
seriesData.push([parseInt(yIndex), dataIndex, dataItem || "-"]);
});
item.type = "heatmap";
item.itemStyle = {
borderColor: "#fff",
borderWidth: isObjValue ? 1 : 0,
emphasis: {
shadowBlur: 10,
shadowColor: "rgba(0, 0, 0, .5)",
},
};
item.label = {
normal: {
show: true,
color: "#444",
},
};
});
optionFormat.legend.show = legendShow;
optionFormat.xAxis.show = !hidexAxis;
optionFormat.xAxis.nameTextStyle = {
color: "#444",
fontSize: 12,
};
optionFormat.xAxis.axisLabel = {
interval: 0,
};
optionFormat.xAxis.splitArea = {
show: true,
};
optionFormat.xAxis.axisLine = {
show: false,
lineStyle: {
color: "#535353",
},
};
seriesData = seriesData.map(function (item) {
return [item[1], item[0], item[2] || "-"];
});
let countVal = 0 ;
if (maxArr.length) {
countVal = _.reduce(maxArr,(count,num)=>count+parseInt(num),0)
onedimen = maxArr.join(",").split(",");
maxNum = Math.max.apply(null, onedimen);
}
let heatNameList = {};
seriesData.forEach((item) => {
if (typeof item[2] != "number") {
heatNameList["k_" + item[0] + "_" + item[1]] = item[2].name;
item[2] = item[2].value;
}
});
// 覆盖格式化后的`option`数据 按需修改
let coverTemp = {
grid: {
left: 60,
right: 0,
top: 5,
bottom: hideVisualMap ? 20 : 52,
},
toolbox: {
show: false,
showTitle: false,
feature: {
saveAsImage: {
icon: this.downloadIcon,
},
},
top: 0,
right: 0,
},
yAxis: {
type: "category",
splitArea: {
show: true,
},
axisTick: {
show: false,
},
axisLine: {
show: false,
lineStyle: {
color: "#535353",
},
},
data: yAxisData,
},
visualMap: {
show: !hideVisualMap,
min: 0,
max: 200,
calculable: true,
orient: "horizontal",
left: "left",
bottom: -10,
itemWidth: 15,
color: visualColor || ["#0068FF", isObjValue ? "#78adfd" : "#cfe4ff"],
},
};
coverTemp.visualMap.max = maxNum;
_grid && (coverTemp.grid = _grid);
const _that = this;
_yAxis && (coverTemp.yAxis = { ...coverTemp.yAxis, ..._yAxis });
let option = JSON.parse(
JSON.stringify({ ...optionFormat, ...coverTemp })
);
option.series.forEach((item) => {
item.data = [];
item.data = seriesData.splice(0, optionFormat.xAxis.data.length); // 多次裁剪 seriesData 数组
item.label = {
show: true,
color: isObjValue ? "#fff" : "#444",
formatter(params) {
if (isObjValue) {
let percent = (params.value[2]*100/countVal).toFixed(2);
return (
heatNameList["k_" + params.value[0] + "_" + params.value[1]] +
"\n\n" +
percent+'%'+
"\n\n"+
_that.toThousands(params.value[2])+_that.$t('format.perNum')
//params.value[2]
);
}
return _that.toThousands(params.value[2]);
},
};
});
if (isObjValue) option.tooltip.show = false;
option.tooltip.formatter = (params, ticket, callback) => {
// let isYeTai = this.chartData.title.text == "业态关联" ? true : false;
let xData = option.xAxis.data,
yData = option.yAxis.data,
htmls = "";
htmls += `<div style="font-size:14px;height:31px;color:#333;border-radius:4px;line-height:31px;padding-left:15px; padding-right:15px; text-align: left; color: #0068FF;">${
yData[params.value[1]]
}</div><div><p style="font-size:13px;padding:4px 15px;color:"#444444"">${
xData[params.value[0]]
}:${painter.$t('iPage.averageheat')}<span style="color:#5093fa;margin-left:2px">${
params.value[2]
}${perUnit}</span></p></div>`;
return htmls;
};
return option;
},
},
created() {},
};
</script>
<style scoped>
</style>