当前位置:   article > 正文

vue 实现 【echarts中综合图表图例】的组件封装及调用_vue 图表插件

vue 图表插件

echarts组件使用参考:https://blog.csdn.net/weixin_50450473/article/details/121510438

目录

图例一

图例二

图例三

图例四

图例五


图例一:

图例二:

图例三:

图例四:

图例五:

图例一

  1. let yData = ["张三", "李四", "张三", "李四", "张三", "张三", "李四", "张三"];
  2. let surplus = [55, 88, 90, 93, 94, 90, 93, 94];
  3. option = {
  4. backgroundColor:'#173565',
  5. legend: {
  6. data: ['分数', '排名'],
  7. x: 'right',
  8. y: '0%',
  9. itemGap: 30,
  10. orient: 'vertical',
  11. textStyle:{
  12. color: '#fff',
  13. fontSize: 15
  14. }
  15. },
  16. grid: {
  17. top: '2%',
  18. left: '0%',
  19. right: '0%',
  20. bottom: '0%',
  21. containLabel: true
  22. },
  23. xAxis: {
  24. type: 'category',
  25. data: yData,
  26. axisLabel: {
  27. fontSize: 10,
  28. color: '#fff'
  29. }
  30. },
  31. yAxis: {
  32. type: 'value',
  33. boundaryGap: true,
  34. axisLabel: {
  35. fontSize: 12,
  36. color: '#fff'
  37. },
  38. interval: 20, //间隔
  39. axisLine: {
  40. show: true
  41. },
  42. splitLine: {
  43. show: false
  44. }
  45. },
  46. series: [
  47. {
  48. name:'分数',
  49. data: surplus,
  50. type: 'bar',
  51. zlevel: 1, // 层级
  52. barWidth: 20,
  53. itemStyle: {
  54. color: function (params) {
  55. var colorList1 = ['#00EAD1', '#1AA67D','#00EAD1', '#1AA67D','#00EAD1', '#1AA67D','#00EAD1', '#1AA67D','#00EAD1', '#1AA67D'];
  56. var colorList2 = ['#0055CB', '#1AA67D','#0055CB', '#1AA67D','#0055CB', '#1AA67D','#0055CB', '#1AA67D','#0055CB', '#1AA67D'];
  57. return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  58. { offset: 0, color: colorList2[params.dataIndex] },
  59. { offset: 1, color: colorList1[params.dataIndex] }
  60. ])
  61. }
  62. },
  63. label: {
  64. normal: {
  65. position: 'top',
  66. show: true,
  67. color: '#fff',
  68. fontSize: 14,
  69. formatter: function (params) {
  70. return params.data
  71. }
  72. }
  73. }
  74. },
  75. {
  76. name: '排名',
  77. type: 'line',
  78. zlevel: 0, // 层级
  79. symbol: 'circle', //拐点样式
  80. symbolSize: 6, //拐点大小
  81. // 折线条的样式
  82. lineStyle: {
  83. color: '#fff',
  84. width: 1
  85. },
  86. // 折线拐点的样式
  87. itemStyle: {
  88. normal: { // 静止时:
  89. color: '#4CF8C5',
  90. borderColor: "#4CF8C5",//拐点的边框颜色
  91. borderWidth: 4
  92. },
  93. emphasis: { // 鼠标经过时:
  94. color: '#4CF8C5',
  95. }
  96. },
  97. areaStyle: {
  98. color: new echarts.graphic.LinearGradient(0, .5, 0, 1, [
  99. {
  100. offset: 0,
  101. color: '#06B89C'
  102. },
  103. {
  104. offset: 1,
  105. color: '#374D6E'
  106. }
  107. ])
  108. },
  109. emphasis: {
  110. focus: 'series'
  111. },
  112. data: [120, 132, 101, 134, 90, 101, 134, 90]
  113. }
  114. ]
  115. }

图例二

1、安装插件

水波纹参考地址:echarts-liquidfill - npm

坑:版本不对导致水波纹不法显示

解决:其中 echarts 版本5以上 和 echarts-liquidfill 版本3对应,echarts 版本5以下 和 echarts-liquidfill 版本2对应;此处 echarts@4.9.0 和 echarts-liquidfill@2.0.6 即可

  1. npm install echarts@4.9.0 --save
  2. npm install echarts-liquidfill@2.0.6 --save

2、页面引入

import 'echarts-liquidfill'

3、option.js

  1. let progress = 50;
  2. let Colors = '71, 228, 229';
  3. let proNum = 100;
  4. option = {
  5. series: [
  6. {
  7. type: 'liquidFill',
  8. waveAnimation: 15,
  9. amplitude: 10,
  10. data: [progress, progress + 0.05, progress + 0.05],
  11. color: [
  12. {
  13. type: 'linear',
  14. x: 0,
  15. y: 1,
  16. x2: 0,
  17. y2: 0,
  18. colorStops: [
  19. {
  20. offset: 1,
  21. color: ['rgba(' + Colors + ',0.58)']
  22. },
  23. {
  24. offset: 0,
  25. color: ['rgba(' + Colors + ',0.2)']
  26. }
  27. ],
  28. global: false
  29. },
  30. {
  31. type: 'linear',
  32. x: 0,
  33. y: 1,
  34. x2: 0,
  35. y2: 0,
  36. colorStops: [
  37. {
  38. offset: 1,
  39. color: ['rgba(' + Colors + ',1)']
  40. },
  41. {
  42. offset: 0,
  43. color: ['rgba(' + Colors + ',0.8)']
  44. }
  45. ],
  46. global: false
  47. },
  48. {
  49. type: 'linear',
  50. x: 0,
  51. y: 1,
  52. x2: 0,
  53. y2: 0,
  54. colorStops: [
  55. {
  56. offset: 1,
  57. color: ['rgba(' + Colors + ',1)']
  58. },
  59. {
  60. offset: 0,
  61. color: ['rgba(' + Colors + ',0)']
  62. }
  63. ],
  64. global: false
  65. }
  66. ],
  67. radius: '85%',
  68. outline: {
  69. itemStyle: {
  70. borderWidth: 6,
  71. borderColor: 'rgba(' + Colors + ',1)'
  72. }
  73. // borderDistance: 0 // 取消缝隙
  74. },
  75. itemStyle: {
  76. opacity: 0.8, // 波浪的透明度
  77. shadowBlur: 0 // 波浪的阴影范围 设置为0不会出现底色为灰色的情况
  78. },
  79. label: {
  80. normal: {
  81. // insideColor: 'transparent', // 固定的文字颜色
  82. formatter: '\n'+'+proNum + '', // 换行,设置位置
  83. fontSize: 16,
  84. color: '#fff'
  85. }
  86. },
  87. backgroundStyle: {
  88. color: 'transparent' // 水球未到的背景颜色
  89. }
  90. }
  91. ]
  92. };

图例三

  1. option = {
  2. xAxis: {
  3. type: 'category',
  4. data: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]
  5. // boundaryGap: false,
  6. },
  7. yAxis: [
  8. {
  9. type: 'value',
  10. name: '℃',
  11. splitLine: {
  12. show: true
  13. }
  14. },
  15. {
  16. type: 'value',
  17. min: -1800,
  18. axisLabel: {
  19. show: true
  20. }
  21. }
  22. ],
  23. series: [
  24. {
  25. data: [
  26. 1200, 1450, 1452, 1600, 1500, 120, 1611, 1600, 120, 1500, 1700, 1500,
  27. 1200, 1200, 1600, 1200
  28. ],
  29. type: 'bar',
  30. stack: 'Total',
  31. markArea: {
  32. label: {
  33. color: '#333',
  34. fontSize: 15
  35. },
  36. data: [
  37. [
  38. {
  39. name: '热回收',
  40. xAxis: 0,
  41. itemStyle: {
  42. color: 'rgba(210,243,202,.5)'
  43. }
  44. },
  45. {
  46. xAxis: 3.4
  47. }
  48. ],
  49. [
  50. {
  51. name: '预热段',
  52. xAxis: 3.4,
  53. itemStyle: {
  54. color: 'rgba(226,212,233,.5)'
  55. }
  56. },
  57. {
  58. xAxis: 7
  59. }
  60. ],
  61. [
  62. {
  63. name: '加热段',
  64. xAxis: 7,
  65. itemStyle: {
  66. color: 'rgba(243,236,208,.8)'
  67. }
  68. },
  69. {
  70. xAxis: 12
  71. }
  72. ],
  73. [
  74. {
  75. name: '均热段',
  76. xAxis: 12,
  77. itemStyle: {
  78. color: 'rgba(249,230,245,.6)'
  79. }
  80. },
  81. {
  82. xAxis: 18
  83. }
  84. ]
  85. ]
  86. }
  87. },
  88. {
  89. name: 'Temperature',
  90. type: 'line',
  91. data: [
  92. 1200, 1450, 1452, 1600, 1850, 1800, 1611, 1600, 120, 1500, 1700, 1500,
  93. 1200, 1200, 1600, 1200
  94. ]
  95. },
  96. {
  97. name: '',
  98. type: 'bar',
  99. yAxisIndex: 1,
  100. itemStyle: {
  101. color: function (params) {
  102. var colorList;
  103. if (params.data >= 0) {
  104. colorList = '#5ccb81';
  105. } else {
  106. colorList = 'red';
  107. }
  108. return colorList;
  109. }
  110. },
  111. data: [100, 120, 30, 30, -20, -10, 0, -5, 6, 7, -8, 9, 10, 12, -40, -20]
  112. }
  113. ]
  114. };

图例四

  1. const dataList=[
  2. {
  3. heatNum:'1',
  4. steelGrade:'GL15544',
  5. datas: [
  6. [0,1500],
  7. [50,600],
  8. [100,1000],
  9. [150,800],
  10. [200,1600],
  11. [250,900],
  12. [300,1800]
  13. ]
  14. },
  15. {
  16. heatNum:'2',
  17. steelGrade:'GL15544',
  18. datas: [
  19. [350,600],
  20. [400,1000],
  21. [450,800],
  22. [500,1600],
  23. [550,900],
  24. [600,1800],
  25. [650,500]
  26. ]
  27. },
  28. {
  29. heatNum:'3',
  30. steelGrade:'GL15544',
  31. datas: [
  32. [700,600],
  33. [750,1100],
  34. [800,800],
  35. [850,1300],
  36. [900,900],
  37. [950,1800],
  38. [1000,600]
  39. ]
  40. }
  41. ]
  42. option = {
  43. title:{
  44. text: '炉号:'+dataList[0].heatNum+'号炉 钢种:'+dataList[0].steelGrade
  45. +' 炉号:'+dataList[1].heatNum+'号炉 钢种:'+dataList[1].steelGrade
  46. +' 炉号:'+dataList[2].heatNum+'号炉 钢种:'+dataList[2].steelGrade,
  47. left:'6%',
  48. top:'3%'
  49. },
  50. grid:{
  51. top:'8%',
  52. left:'6%',
  53. right:'2%',
  54. bottom:'5%'
  55. },
  56. xAxis:[
  57. {
  58. type: 'value',
  59. show: false,
  60. max: 1000,
  61. position:'top'
  62. },
  63. {
  64. type: 'category',
  65. data: ['14:00:00','14:02:00', '14:04:00', '14:06:00', '14:08:00', '14:10:00',
  66. '14:12:00', '14:14:00', '14:16:00','14:18:00'],
  67. axisLine:{
  68. show:false
  69. },
  70. axisTick:{
  71. show:false
  72. }
  73. },
  74. ],
  75. yAxis: {
  76. type: 'value',
  77. max:1800,
  78. min:0,
  79. splitNumber:4,
  80. axisLabel: {
  81. formatter: '{value} ℃'
  82. },
  83. axisLine:{
  84. show:false
  85. },
  86. axisTick:{
  87. show:false
  88. }
  89. },
  90. visualMap:[
  91. {
  92. show:false,
  93. splitNumber:3,
  94. seriesIndex:0, // 指第几个图形
  95. pieces:[
  96. {
  97. gte:0,
  98. lte:1200,
  99. color:'red'
  100. },
  101. {
  102. gte:1200,
  103. lte:1500,
  104. color:'green'
  105. },
  106. {
  107. gte:1500,
  108. lte:1800,
  109. color:'red'
  110. }
  111. ]
  112. },
  113. {
  114. show:false,
  115. splitNumber:3,
  116. seriesIndex:1,
  117. pieces:[
  118. {
  119. gte:0,
  120. lte:1300,
  121. color:'red'
  122. },
  123. {
  124. gte:1300,
  125. lte:1600,
  126. color:'green'
  127. },
  128. {
  129. gte:1600,
  130. lte:1800,
  131. color:'red'
  132. }
  133. ]
  134. },
  135. {
  136. show:false,
  137. splitNumber:3,
  138. seriesIndex:2,
  139. pieces:[
  140. {
  141. gte:0,
  142. lte:800,
  143. color:'red'
  144. },
  145. {
  146. gte:800,
  147. lte:1100,
  148. color:'green'
  149. },
  150. {
  151. gte:1100,
  152. lte:1800,
  153. color:'red'
  154. }
  155. ]
  156. }
  157. ],
  158. series: [
  159. {
  160. type: 'line',
  161. smooth:false,
  162. data: [
  163. [0,1500],
  164. [50,600],
  165. [100,1000],
  166. [150,800],
  167. [200,1600],
  168. [250,900],
  169. [300,1800]
  170. ],
  171. markArea:{
  172. itemStyle:{
  173. color:'rgba(134,222,165,.4)'
  174. },
  175. data:[
  176. [{
  177. name:'1111',
  178. yAxis:1200,
  179. xAxis:0
  180. },{
  181. yAxis:1500,
  182. xAxis:300
  183. }]
  184. ]
  185. }
  186. },
  187. {
  188. type: 'line',
  189. smooth:false,
  190. data: [
  191. [350,600],
  192. [400,1000],
  193. [450,800],
  194. [500,1600],
  195. [550,900],
  196. [600,1800],
  197. [650,500]
  198. ],
  199. markArea:{
  200. itemStyle:{
  201. color:'rgba(134,222,165,.4)'
  202. },
  203. data:[
  204. [{
  205. name:'2222',
  206. yAxis:1300,
  207. xAxis:350
  208. },{
  209. yAxis:1600,
  210. xAxis:650
  211. }]
  212. ]
  213. }
  214. },
  215. {
  216. type: 'line',
  217. smooth:false,
  218. data: [
  219. [700,600],
  220. [750,1100],
  221. [800,800],
  222. [850,1300],
  223. [900,900],
  224. [950,1800],
  225. [1000,600]
  226. ],
  227. markArea:{
  228. itemStyle:{
  229. color:'rgba(134,222,165,.4)'
  230. },
  231. data:[
  232. [{
  233. name:'3333',
  234. yAxis:800,
  235. xAxis:700
  236. },{
  237. yAxis:1100,
  238. xAxis:1000
  239. }]
  240. ]
  241. }
  242. }
  243. ]
  244. };

图例五

  1. let datas = [
  2. { name: '余装定理', diffic: 'D', master: 65, num: 7 },
  3. { name: '三角形边长', diffic: 'B', master: 75, num: 9 },
  4. { name: '三角形面积', diffic: 'A', master: 52, num: 2 },
  5. { name: '三角形对角', diffic: 'C', master: 55, num: 5 },
  6. { name: '勾股定理', diffic: 'A', master: 70, num: 6 }
  7. ];
  8. const colorList = ['#a7d691', '#f18585', '#fbd379', '#8fcde5'];
  9. let className = ['A', 'B', 'C', 'D'];
  10. let xName = [];
  11. let series = [];
  12. datas.forEach((da) => {
  13. xName.push([da.name, da.master, da.diffic, da.num]);
  14. });
  15. className.forEach((cl) => {
  16. series.push(
  17. {
  18. type: 'line',
  19. smooth: true,
  20. data: datas.map((m) => {
  21. return m.master;
  22. }),
  23. color: '#999',
  24. label: {
  25. show: true,
  26. position: 'center',
  27. padding: [15, 0, 0, -10],
  28. formatter: function (value) {
  29. return value.data + '%';
  30. }
  31. }
  32. },
  33. {
  34. name: cl,
  35. type: 'scatter',
  36. symbol: 'pin', //'circle', 'rect', 'roundRect', 'triangle', 'diamond', 'pin', 'arrow'
  37. symbolSize: function (data) {
  38. return data[3] * 10;
  39. },
  40. symbolColor: 'red',
  41. itemStyle: {
  42. normal: {
  43. color: function (data) {
  44. if (data.data[2] === 'A') {
  45. return colorList[1];
  46. } else if (data.data[2] === 'B') {
  47. return colorList[2];
  48. } else if (data.data[2] === 'C') {
  49. return colorList[3];
  50. } else if (data.data[2] === 'D') {
  51. return colorList[0];
  52. }
  53. }
  54. }
  55. },
  56. label: {
  57. show: true,
  58. color: '#000',
  59. formatter: function (value) {
  60. return value.data[3] + '题';
  61. },
  62. },
  63. data: xName
  64. });
  65. });
  66. option = {
  67. textStyle: {
  68. color: '#666'
  69. },
  70. yAxis: {
  71. name: '掌握率(%)',
  72. max: 100,
  73. min: 0,
  74. splitLine: {
  75. lineStyle: {
  76. type: 'dashed'
  77. }
  78. },
  79. scale: false
  80. },
  81. xAxis: {
  82. name: '知识点',
  83. data: datas.map((m) => {
  84. return m.name;
  85. })
  86. },
  87. color: colorList,
  88. legend: {
  89. show: true,
  90. top: 0,
  91. itemGap: 30,
  92. data: className
  93. },
  94. series: series
  95. };

      希望我的愚见能够帮助你哦~,若有不足之处,还望指出,你们有更好的解决方法,欢迎大家在评论区下方留言支持,大家一起相互学习参考呀~

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/904340?site=
推荐阅读
相关标签
  

闽ICP备14008679号