widgetHeatmap.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <div :style="styleObj">
  3. <v-chart :options="options" autoresize/>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: "widgetHeatmap",
  9. components: {},
  10. props: {
  11. value: Object,
  12. ispreview: Boolean,
  13. },
  14. data() {
  15. return {
  16. options: {
  17. title: {
  18. text: "",
  19. left: "center",
  20. textStyle: {
  21. color: "#fff",
  22. },
  23. },
  24. tooltip: {
  25. position: "top",
  26. show: true,
  27. textStyle: {},
  28. },
  29. grid: {
  30. height: "90%",
  31. width: "90%",
  32. top: 10,
  33. left: 20,
  34. },
  35. xAxis: {
  36. name: "",
  37. type: "category",
  38. axisLabel: {
  39. show: true,
  40. color: "#0f0",
  41. },
  42. data: [],
  43. splitArea: {
  44. show: false,
  45. },
  46. nameTextStyle: {
  47. color: "",
  48. fontSize: 14,
  49. },
  50. },
  51. yAxis: {
  52. name: "",
  53. type: "category",
  54. axisLabel: {
  55. show: true,
  56. color: "#0f0",
  57. },
  58. data: [],
  59. splitArea: {
  60. show: false,
  61. },
  62. nameTextStyle: {
  63. color: "",
  64. fontSize: 14,
  65. },
  66. },
  67. visualMap: {
  68. show: true,
  69. min: 0,
  70. max: 5000,
  71. calculable: true,
  72. orient: "horizontal",
  73. left: "center",
  74. bottom: 0,
  75. inRange: {
  76. color: [],
  77. },
  78. textStyle: {
  79. fontSize: 14,
  80. color: "#fff",
  81. },
  82. },
  83. series: [
  84. {
  85. name: "",
  86. type: "heatmap",
  87. data: [],
  88. label: {
  89. show: false,
  90. fontSize: 16,
  91. },
  92. emphasis: {
  93. itemStyle: {
  94. shadowBlur: 10,
  95. shadowColor: "rgba(0, 0, 0, 0.5)",
  96. },
  97. },
  98. },
  99. ],
  100. },
  101. optionsStyle: {}, // 样式
  102. optionsData: {}, // 数据
  103. optionsCollapse: {}, // 图标属性
  104. optionsSetup: {},
  105. };
  106. },
  107. computed: {
  108. styleObj() {
  109. return {
  110. position: this.ispreview ? "absolute" : "static",
  111. width: this.optionsStyle.width + "px",
  112. height: this.optionsStyle.height + "px",
  113. left: this.optionsStyle.left + "px",
  114. top: this.optionsStyle.top + "px",
  115. background: this.optionsSetup.background,
  116. };
  117. },
  118. },
  119. watch: {
  120. value: {
  121. handler(val) {
  122. this.optionsStyle = val.position;
  123. this.optionsData = val.data;
  124. this.optionsCollapse = val.collapse;
  125. this.optionsSetup = val.setup;
  126. this.editorOptions();
  127. },
  128. deep: true,
  129. },
  130. },
  131. created() {
  132. this.optionsStyle = this.value.position;
  133. this.optionsData = this.value.data;
  134. this.optionsCollapse = this.value.collapse;
  135. this.optionsSetup = this.value.setup;
  136. this.editorOptions();
  137. },
  138. methods: {
  139. // 修改图标options属性
  140. editorOptions() {
  141. this.setOptionsTitle();
  142. this.setOptionsX();
  143. this.setOptionsY();
  144. this.setOptionsSeries();
  145. this.setOptionsMargin();
  146. this.setOptionsVisualMap();
  147. this.setOptionsData();
  148. },
  149. // 标题修改
  150. setOptionsTitle() {
  151. const optionsSetup = this.optionsSetup;
  152. const title = {};
  153. title.text = optionsSetup.titleText;
  154. title.show = optionsSetup.isNoTitle;
  155. title.left = optionsSetup.textAlign;
  156. title.textStyle = {
  157. color: optionsSetup.textColor,
  158. fontSize: optionsSetup.textFontSize,
  159. fontWeight: optionsSetup.textFontWeight,
  160. fontStyle: optionsSetup.textFontStyle,
  161. };
  162. title.subtext = optionsSetup.subText;
  163. title.subtextStyle = {
  164. color: optionsSetup.subTextColor,
  165. fontWeight: optionsSetup.subTextFontWeight,
  166. fontSize: optionsSetup.subTextFontSize,
  167. fontStyle: optionsSetup.subTextFontStyle,
  168. };
  169. this.options.title = title;
  170. },
  171. // X轴设置
  172. setOptionsX() {
  173. const optionsSetup = this.optionsSetup;
  174. const xAxis = {
  175. type: "category",
  176. // 坐标轴是否显示
  177. show: optionsSetup.hideX,
  178. // 坐标轴名称
  179. name: optionsSetup.nameX,
  180. nameTextStyle: {
  181. color: optionsSetup.nameColorX,
  182. fontSize: optionsSetup.nameFontSizeX
  183. },
  184. // 轴反转
  185. inverse: optionsSetup.reversalX,
  186. axisLabel: {
  187. show: true,
  188. // 文字间隔
  189. interval: optionsSetup.textInterval,
  190. // 文字角度
  191. rotate: optionsSetup.textAngleX,
  192. textStyle: {
  193. // 坐标文字颜色
  194. color: optionsSetup.colorX,
  195. fontSize: optionsSetup.fontSizeX
  196. }
  197. },
  198. axisLine: {
  199. show: true,
  200. lineStyle: {
  201. color: optionsSetup.lineColorX,
  202. width: optionsSetup.lineWidthX,
  203. }
  204. },
  205. };
  206. this.options.xAxis = xAxis;
  207. },
  208. // Y轴设置
  209. setOptionsY() {
  210. const optionsSetup = this.optionsSetup;
  211. const yAxis = {
  212. type: "value",
  213. scale: optionsSetup.scale,
  214. // 均分
  215. splitNumber: optionsSetup.splitNumberY,
  216. // 坐标轴是否显示
  217. show: optionsSetup.isShowY,
  218. // 坐标轴名称
  219. name: optionsSetup.textNameY,
  220. nameTextStyle: {
  221. color: optionsSetup.nameColorY,
  222. fontSize: optionsSetup.nameFontSizeY
  223. },
  224. // 轴反转
  225. inverse: optionsSetup.reversalY,
  226. axisLabel: {
  227. show: true,
  228. // 文字角度
  229. rotate: optionsSetup.textAngleY,
  230. textStyle: {
  231. // 坐标文字颜色
  232. color: optionsSetup.colorY,
  233. fontSize: optionsSetup.fontSizeY
  234. }
  235. },
  236. axisLine: {
  237. show: true,
  238. lineStyle: {
  239. color: optionsSetup.lineColorY,
  240. width: optionsSetup.lineWidthY,
  241. }
  242. },
  243. };
  244. this.options.yAxis = yAxis;
  245. },
  246. // 数值设定
  247. setOptionsSeries() {
  248. const optionsSetup = this.optionsSetup;
  249. const lable = {
  250. show: optionsSetup.isShow,
  251. textStyle: {
  252. fontSize: optionsSetup.fontSize,
  253. color: optionsSetup.subTextColor,
  254. fontWeight: optionsSetup.fontWeight
  255. }
  256. }
  257. this.options.series[0].label = lable;
  258. },
  259. // 边距设置
  260. setOptionsMargin() {
  261. const optionsSetup = this.optionsSetup;
  262. const grid = {
  263. left: optionsSetup.marginLeft,
  264. right: optionsSetup.marginRight,
  265. bottom: optionsSetup.marginBottom,
  266. top: optionsSetup.marginTop,
  267. containLabel: true
  268. };
  269. this.options.grid = grid;
  270. },
  271. // tooltip 设置
  272. setOptionsTooltip() {
  273. const optionsSetup = this.optionsSetup;
  274. const tooltip = {
  275. trigger: "item",
  276. position: "top",
  277. show: true,
  278. textStyle: {
  279. color: optionsSetup.tipsColor,
  280. fontSize: optionsSetup.tipsFontSize,
  281. }
  282. };
  283. this.options.tooltip = tooltip;
  284. },
  285. // 图设置
  286. setOptionsVisualMap() {
  287. const optionsSetup = this.optionsSetup;
  288. const visualMap = this.options.visualMap;
  289. visualMap.show = optionsSetup.isShowLegend;
  290. visualMap.min = optionsSetup.dataMin;
  291. visualMap.max = optionsSetup.dataMax;
  292. visualMap.textStyle = {
  293. fontSize : optionsSetup.legendFontSize,
  294. color : optionsSetup.legendColor
  295. };
  296. visualMap.inRange.color = optionsSetup.legendColorList.map((x) => {
  297. return x.color;
  298. });
  299. visualMap.left = optionsSetup.lateralPosition;
  300. visualMap.top = optionsSetup.longitudinalPosition;
  301. visualMap.bottom = optionsSetup.longitudinalPosition;
  302. visualMap.orient = optionsSetup.layoutFront;
  303. visualMap.itemWidth = optionsSetup.legendWidth;
  304. },
  305. setOptionsData() {
  306. const optionsData = this.optionsData; // 数据类型 静态 or 动态
  307. optionsData.dataType == "staticData"
  308. ? this.staticDataFn(optionsData.staticData)
  309. : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
  310. },
  311. //去重
  312. setUnique(arr) {
  313. let newArr = [];
  314. arr.forEach(item => {
  315. return newArr.includes(item) ? '' : newArr.push(item);
  316. });
  317. return newArr;
  318. },
  319. staticDataFn(val) {
  320. const data = [];
  321. let xAxisList = [];
  322. let yAxisList = [];
  323. for (const i in val) {
  324. xAxisList[i] = val[i].axis;
  325. yAxisList[i] = val[i].yaxis;
  326. data[i] = [val[i].axis,val[i].yaxis,val[i].num]
  327. }
  328. xAxisList = this.setUnique(xAxisList);
  329. yAxisList = this.setUnique(yAxisList);
  330. this.options.xAxis.data = xAxisList;
  331. this.options.yAxis.data = yAxisList;
  332. this.options.series[0].data = data;
  333. },
  334. dynamicDataFn(val, refreshTime) {
  335. if (!val) return;
  336. if (this.ispreview) {
  337. this.getEchartData(val);
  338. this.flagInter = setInterval(() => {
  339. this.getEchartData(val);
  340. }, refreshTime);
  341. } else {
  342. this.getEchartData(val);
  343. }
  344. },
  345. getEchartData(val) {
  346. const data = this.queryEchartsData(val);
  347. data.then((res) => {
  348. this.renderingFn(res);
  349. });
  350. },
  351. renderingFn(val) {
  352. this.options.xAxis.data = val.xAxis;
  353. this.options.yAxis.data = val.yAxis;
  354. this.options.series[0].data = val.series;
  355. },
  356. },
  357. };
  358. </script>
  359. <style scoped lang="scss">
  360. .echarts {
  361. width: 100%;
  362. height: 100%;
  363. overflow: hidden;
  364. }
  365. </style>