• tooltip里面画echarts图


    第一步:

    第二步;

    完整代码:

    1. //协作工作受理分析圆柱形
    2. workLineChart(xData, yData) {
    3. let that = this;
    4. let option = {
    5. backgroundColor: "#061326",
    6. grid: {
    7. top: "10%",
    8. bottom: "5%",
    9. left: "5%",
    10. right: "5%",
    11. containLabel: true
    12. },
    13. tooltip: {
    14. trigger: "axis",
    15. axisPointer: {
    16. type: "shadow" // 默认为直线,可选为:'line' | 'shadow'
    17. },
    18. triggerOn: "click",
    19. // triggerOn: 'mousemove|click',
    20. formatter: (params, ticket, callback) => {
    21. let htmlStr = `<div id="tooltipChart" ref='tooltipChart' style='width:280px;height:280px;'></div>`;
    22. callback(that.tooltipEchartData(params[0].name, params[0].value));
    23. return htmlStr;
    24. },
    25. extraCssText: "z-index:99999",
    26. // backgroundColor: "rgba(0,0,0,0.9)",
    27. backgroundColor: "rgba(17,49,94,0.9)",
    28. borderWidth: 1,
    29. borderColor: "rgba(42, 92, 176, .6)",
    30. // textStyle: {
    31. // color: "rgba(255,255,255,1)",
    32. // }
    33. transitionDuration: 0 // 让toolltip紧跟鼠标
    34. // position: function(point, params, dom, rect, size) {
    35. // // 鼠标坐标和提示框位置的参考坐标系是:以外层div的左上角那一点为原点,x轴向右,y轴向下
    36. // // 提示框位置
    37. // var x = 0; // x坐标位置
    38. // var y = 0; // y坐标位置
    39. // // 当前鼠标位置
    40. // var pointX = point[0];
    41. // var pointY = point[1];
    42. // // 外层div大小
    43. // // var viewWidth = size.viewSize[0];
    44. // // var viewHeight = size.viewSize[1];
    45. // // 提示框大小
    46. // var boxWidth = size.contentSize[0];
    47. // var boxHeight = size.contentSize[1];
    48. // // boxWidth > pointX 说明鼠标左边放不下提示框
    49. // if (boxWidth > pointX) {
    50. // x = 50;
    51. // } else {
    52. // // 左边放的下
    53. // x = pointX - boxWidth;
    54. // }
    55. // // boxHeight > pointY 说明鼠标上边放不下提示框
    56. // if (boxHeight > pointY) {
    57. // y = -300;
    58. // } else {
    59. // // 上边放得下
    60. // y = pointY - boxHeight;
    61. // }
    62. // return [x, y];
    63. // }
    64. },
    65. animation: false,
    66. xAxis: [
    67. {
    68. type: "category",
    69. data: xData,
    70. axisTick: {
    71. show: false,
    72. alignWithLabel: true
    73. },
    74. axisLine: {
    75. show: false,
    76. lineStyle: {
    77. color: "#82b0ec"
    78. }
    79. },
    80. splitLine: {
    81. show: true,
    82. lineStyle: { color: "#222D3E", width: 1, type: "solid" }
    83. },
    84. axisLabel: {
    85. interval: 0,
    86. formatter: function(params) {
    87. let newParamsName = "";
    88. const paramsNameNumber = params.length; // 文字总长度
    89. const provideNumber = 4; //一行显示几个字
    90. const rowNumber = Math.ceil(paramsNameNumber / provideNumber);
    91. if (paramsNameNumber > provideNumber) {
    92. for (let p = 0; p < rowNumber; p++) {
    93. const start = p * provideNumber;
    94. const end = start + provideNumber;
    95. const tempStr =
    96. p === rowNumber - 1
    97. ? params.substring(start, paramsNameNumber)
    98. : params.substring(start, end) + "\n";
    99. newParamsName += tempStr;
    100. }
    101. } else {
    102. newParamsName = params;
    103. }
    104. return newParamsName;
    105. },
    106. textStyle: {
    107. color: "#fff"
    108. }
    109. }
    110. }
    111. ],
    112. yAxis: [
    113. {
    114. show: true,
    115. type: "value",
    116. axisLabel: {
    117. textStyle: {
    118. color: "#fff"
    119. }
    120. },
    121. splitLine: {
    122. show: true,
    123. lineStyle: { color: "#222D3E", width: 1, type: "solid" }
    124. },
    125. axisLine: {
    126. show: false
    127. },
    128. textStyle: {
    129. color: "#00FFEF"
    130. }
    131. }
    132. ],
    133. series: [
    134. {
    135. name: "",
    136. type: "pictorialBar",
    137. symbolSize: [30, 10],
    138. symbolOffset: [0, -6], // 上部椭圆
    139. symbolPosition: "end",
    140. z: 12,
    141. // "barWidth": "0",
    142. label: {
    143. normal: {
    144. show: true,
    145. position: "top",
    146. fontSize: fontChart(12),
    147. fontWeight: "bold",
    148. color: "#69DDFA"
    149. // background:"ur"
    150. }
    151. },
    152. color: "#2DB1EF",
    153. data: yData
    154. },
    155. {
    156. name: "",
    157. type: "pictorialBar",
    158. symbolSize: [30, 10],
    159. symbolOffset: [0, 0], // 下部椭圆
    160. // "barWidth": "20",
    161. z: 12,
    162. color: "rgba(43, 67, 165, 0.5)",
    163. data: yData
    164. },
    165. {
    166. type: "bar",
    167. //silent: true,
    168. barWidth: "30",
    169. barGap: "10%", // Make series be overlap
    170. barCateGoryGap: "10%",
    171. itemStyle: {
    172. normal: {
    173. color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [
    174. {
    175. offset: 0,
    176. color: "rgba(82, 180, 249, 1)"
    177. },
    178. {
    179. offset: 1,
    180. color: "rgba(43, 67, 165, 0.35)"
    181. }
    182. ]),
    183. opacity: 0.8
    184. }
    185. },
    186. data: yData
    187. }
    188. ]
    189. };
    190. let myChart = this.$echarts.init(this.$refs.workLineChart);
    191. if (myChart) {
    192. myChart.setOption(option, true);
    193. window.addEventListener("resize", function() {
    194. myChart.resize();
    195. });
    196. }
    197. // var current = -1;
    198. // var dataLen1 = option.series[0].data.length;
    199. // setInterval(() => {
    200. // // 取消之前高亮的图形
    201. // myChart.dispatchAction({
    202. // type: "downplay",
    203. // seriesIndex: 0,
    204. // dataIndex: current
    205. // });
    206. // current = (current + 1) % dataLen1;
    207. // // 高亮当前图形
    208. // myChart.dispatchAction({
    209. // type: "highlight",
    210. // seriesIndex: 0,
    211. // dataIndex: current
    212. // });
    213. // // 显示 tooltip
    214. // myChart.dispatchAction({
    215. // type: "showTip",
    216. // seriesIndex: 0,
    217. // dataIndex: current
    218. // });
    219. // }, 2000);
    220. // this.setIntervals(option, myChart)
    221. },
    222. // 协作工作受理分析下钻数据
    223. tooltipEchartData(name, value) {
    224. let params = Object.assign({}, this.params);
    225. params.secondTag = name;
    226. //协作工作受理分析下钻
    227. getAction("/getSecondCollaborative", params).then(res => {
    228. let arr = res.data.collaborativeList;
    229. // console.log(arr, "协作工作受理分析下钻");
    230. let Data = [];
    231. let title = name + " " + "总数 : " + value + "次";
    232. if (arr.length > 0) {
    233. arr.forEach(item => {
    234. let obj = { value: item.count, name: item.dataType };
    235. Data.push(obj);
    236. });
    237. }
    238. this.$nextTick(() => {
    239. if (!document.getElementById("tooltipChart")) return;
    240. let myChart = this.$echarts.init(
    241. document.getElementById("tooltipChart")
    242. );
    243. // this.myChartTwo.clear();
    244. this.setTooltipEchart(Data, title, myChart);
    245. });
    246. });
    247. },
    248. // 协作工作受理分析圆柱形 点击出现饼图
    249. setTooltipEchart(data, titleText, myChart) {
    250. const colorList = [
    251. {
    252. x: 0,
    253. y: 0,
    254. x2: 0,
    255. y2: 1,
    256. colorStops: [
    257. {
    258. offset: 1,
    259. color: "#006AFF" // 0% 处的颜色
    260. },
    261. {
    262. offset: 0,
    263. color: "#8CE2FF" // 100% 处的颜色
    264. }
    265. ]
    266. },
    267. {
    268. x: 0,
    269. y: 0,
    270. x2: 0,
    271. y2: 1,
    272. colorStops: [
    273. {
    274. offset: 0,
    275. color: "#92F092" // 0% 处的颜色
    276. },
    277. {
    278. offset: 1,
    279. color: "#4BB84B" // 100% 处的颜色
    280. }
    281. ]
    282. },
    283. {
    284. x: 0,
    285. y: 0,
    286. x2: 0,
    287. y2: 1,
    288. colorStops: [
    289. {
    290. offset: 0,
    291. color: "#8BA7D8" // 0% 处的颜色
    292. },
    293. {
    294. offset: 1,
    295. color: "#8FABDA" // 100% 处的颜色
    296. }
    297. ]
    298. },
    299. {
    300. x: 0,
    301. y: 0,
    302. x2: 0,
    303. y2: 1,
    304. colorStops: [
    305. {
    306. offset: 0,
    307. color: "#22B3FF" // 0% 处的颜色
    308. },
    309. {
    310. offset: 1,
    311. color: "#62C6FA" // 100% 处的颜色
    312. }
    313. ]
    314. }
    315. ];
    316. let option = {
    317. color: colorList,
    318. title: {
    319. text: titleText,
    320. show: true, // 是否显示标题,默认 true
    321. padding: [10, 0, 5, 0],
    322. textStyle: {
    323. color: "white",
    324. fontSize: fontChart(16),
    325. fontFamily: "Alibaba PuHuiTi",
    326. fontWeight: 600
    327. },
    328. left: "center"
    329. },
    330. tooltip: {
    331. trigger: "item",
    332. show: false,
    333. borderColor: "rgba(255,255,255,.3)",
    334. backgroundColor: "rgba(13,5,30,.6)",
    335. borderWidth: 1,
    336. padding: 5,
    337. textStyle: {
    338. color: "#fff"
    339. }
    340. },
    341. legend: {
    342. // orient: "vertical",
    343. bottom: 10,
    344. // right: 5,
    345. itemWidth: 20,
    346. itemHeight: 10,
    347. itemGap: 15,
    348. borderRadius: 4,
    349. textStyle: {
    350. color: "white",
    351. fontFamily: "Alibaba PuHuiTi",
    352. fontSize: fontChart(16),
    353. fontWeight: 400
    354. }
    355. },
    356. series: [
    357. {
    358. name: "",
    359. type: "pie",
    360. radius: ["0%", "40%"],
    361. center: ["45%", "50%"],
    362. itemStyle: {
    363. //边框
    364. borderWidth: 0,
    365. borderColor: "#15213F"
    366. },
    367. // avoidLabelOverlap: false,
    368. label: {
    369. show: true,
    370. formatter: e => {
    371. return "{value|" + e.value + "%" + "}\n{name|" + e.name + "}";
    372. },
    373. rich: {
    374. // 改变标示文字的颜色
    375. name: {
    376. color: "#F0F0F0",
    377. fontSize: fontChart(16)
    378. },
    379. value: {
    380. color: "#F0F0F0",
    381. fontSize: fontChart(18)
    382. }
    383. }
    384. },
    385. labelLine: {
    386. show: true
    387. },
    388. data: data
    389. }
    390. ]
    391. };
    392. // this.myChartTwo.setOption(option);
    393. myChart.setOption(option);
    394. },

  • 相关阅读:
    顺丰快递:请签收MySQL灵魂十连
    git常用命令
    Spring框架笔记
    淘客返利平台的跨平台开发实践
    APP稳定性测试工具:Monkey
    webGL编程指南 第五章 MultiTexture.html
    目标检测——Yolo系列
    熟悉Redis6
    python实现微信新版v3的jsapi支付
    【Python】【技能树评测】技巧实例-说明改进和实践【04】访问限制
  • 原文地址:https://blog.csdn.net/weixin_50885665/article/details/133882197