农经大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 2 седмици
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import * as echarts from 'echarts';
  2. import elementResizeDetectorMaker from 'element-resize-detector';
  3. export default {
  4. props: {
  5. id: {
  6. type: String,
  7. default: 'bar'
  8. },
  9. data: {
  10. type: Array,
  11. default: function () {
  12. return [
  13. {
  14. name: '1月',
  15. value: '10'
  16. },
  17. {
  18. name: '2月',
  19. value: '19'
  20. }
  21. ];
  22. }
  23. },
  24. unit: {
  25. type: String,
  26. default: '单位:万元'
  27. },
  28. color: {
  29. type: Array,
  30. default: function () {
  31. return ['rgba(15, 252, 252, 1)', 'rgba(53, 197, 124, 1)']
  32. }
  33. }
  34. },
  35. data () {
  36. return {
  37. chart: null
  38. };
  39. },
  40. mounted () {
  41. this.initChart();
  42. },
  43. computed: {
  44. },
  45. methods: {
  46. // 设置监听器 页面尺寸变化重新绘制图表
  47. initResizeCallBack () {
  48. const erd = elementResizeDetectorMaker();
  49. erd.listenTo(document.getElementById(this.id), () => {
  50. this.$nextTick(() => {
  51. this.chart.resize();
  52. });
  53. });
  54. },
  55. initChart () {
  56. this.chart = echarts.init(document.getElementById(this.id));
  57. this.chartSetOption();
  58. },
  59. chartSetOption () {
  60. let xAxisData = [];
  61. let data = [];
  62. this.data.forEach(item => {
  63. xAxisData.push(item.name)
  64. data.push(item.value)
  65. });
  66. const option = {
  67. color: ["#3398DB"],
  68. tooltip: {
  69. trigger: "axis",
  70. axisPointer: {
  71. type: "line",
  72. lineStyle: {
  73. opacity: 0,
  74. },
  75. }
  76. },
  77. legend: {
  78. data: ["直接访问", "背景"],
  79. show: false,
  80. },
  81. grid: {
  82. left: "0%",
  83. right: "0%",
  84. bottom: "5%",
  85. top: "15%",
  86. containLabel: true,
  87. z: 22,
  88. },
  89. xAxis: [
  90. {
  91. splitArea: {
  92. show: false,
  93. areaStyle: {
  94. color: ['RGBA(13, 31, 64, 1)']
  95. }
  96. },
  97. splitLine: {
  98. show: false,
  99. lineStyle: {
  100. color: ['rgba(18, 40, 83, 1)'],
  101. width: 100
  102. }
  103. },
  104. type: "category",
  105. gridIndex: 0,
  106. data: xAxisData,
  107. axisTick: {
  108. alignWithLabel: true,
  109. },
  110. axisLine: {
  111. lineStyle: {
  112. color: "#0c3b71",
  113. },
  114. },
  115. axisLabel: {
  116. show: true,
  117. color: 'rgba(185, 211, 235, 1)'
  118. },
  119. },
  120. ],
  121. yAxis: [
  122. {
  123. type: "value",
  124. name: this.unit,
  125. nameTextStyle: {
  126. color: 'rgba(185, 211, 235, 1)'
  127. },
  128. axisLabel: {
  129. formatter: "{value}",
  130. textStyle: {
  131. color: "rgba(185, 211, 235, 1)",
  132. },
  133. },
  134. axisLine: {
  135. lineStyle: {
  136. color: "#27b4c2",
  137. },
  138. },
  139. axisTick: {
  140. show: false,
  141. },
  142. splitLine: {
  143. show: true,
  144. lineStyle: {
  145. color: "#11366e",
  146. },
  147. },
  148. },
  149. {
  150. type: "value",
  151. gridIndex: 0,
  152. max: 100,
  153. splitNumber: 12,
  154. splitLine: {
  155. show: false,
  156. },
  157. axisLine: {
  158. show: false,
  159. },
  160. axisTick: {
  161. show: false,
  162. },
  163. axisLabel: {
  164. show: false,
  165. }
  166. },
  167. ],
  168. series: [
  169. {
  170. name: "合格率",
  171. type: "bar",
  172. barWidth: 15,
  173. xAxisIndex: 0,
  174. yAxisIndex: 0,
  175. showBackground: false,
  176. backgroundStyle: {
  177. shadowBlur: 10,
  178. color: 'rgba(18, 40, 83, 1)'
  179. },
  180. itemStyle: {
  181. normal: {
  182. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  183. {
  184. offset: 0,
  185. color: this.color[0],
  186. },
  187. {
  188. offset: 1,
  189. color: this.color[1],
  190. },
  191. ]),
  192. },
  193. },
  194. data: data,
  195. zlevel: 11,
  196. },
  197. {
  198. type: 'custom',
  199. itemStyle: {
  200. color: 'rgba(18, 40, 83, 0.4)'
  201. },
  202. renderItem: function (params, api) {
  203. //获取对应类目的axisTick中心点坐标
  204. var start = api.coord([api.value(0)]);
  205. //通过坐标系的宽度和类目数,计算单个类目的背景
  206. var width = (params.coordSys.width / 7) * 0.6;
  207. return {
  208. type: 'rect',
  209. shape: {
  210. // 相对左上角坐标
  211. x: start[0] - width / 2,
  212. y: params.coordSys.y,
  213. width: width,
  214. height: params.coordSys.height,
  215. },
  216. style: api.style()
  217. };
  218. },
  219. data: [100, 100, 100, 100, 100, 100, 100]
  220. },
  221. ],
  222. };;
  223. this.chart.setOption(option);
  224. this.initResizeCallBack();
  225. }
  226. }
  227. };