chartD.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="pieView">
  3. <div style="height:14%;line-height:30px;text-align: left;padding-left: 10px;padding-top: 10px; margin-bottom: -50px; color: white;">
  4. {{ info.title || "" }}
  5. </div>
  6. <div style="width: 100%; height: 95%; display: inline-block; overflow: hidden">
  7. <div :id="info.id" style="width: 100%; height: 100%; overflow: hidden;padding-right: 10px;" />
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import * as echarts from 'echarts'
  13. export default {
  14. props: {
  15. info: {
  16. type: Object,
  17. default: function () {
  18. return {}
  19. }
  20. }
  21. },
  22. data () {
  23. return {
  24. showChart: true,
  25. option: {
  26. tooltip: {
  27. trigger: 'axis',
  28. axisPointer: {
  29. type: 'cross',
  30. crossStyle: {
  31. color: '#999'
  32. }
  33. }
  34. },
  35. toolbox: {
  36. show: true,
  37. feature: {
  38. dataView: { show: true, readOnly: false,
  39. optionToContent: function (opt) {
  40. var axisData = opt.xAxis[0].data// x轴作为条件,y轴需改成yAxis[0].data;
  41. var series = opt.series
  42. var tdHeads = '<td style="padding:0 10px">年份</td>'
  43. series.forEach(function (item) {
  44. tdHeads += '<td style="padding: 0 10px">' + item.name + '</td>'
  45. })
  46. var table = '<table border="1" style="margin-left:20px;border-collapse:collapse;font-size:14px;text-align:center;color:#666"><tbody><tr>' + tdHeads + '</tr>'
  47. var tdBodys = ''
  48. for (var i = 0, l = axisData.length; i < l; i++) {
  49. for (var j = 0; j < series.length; j++) {
  50. if (typeof (series[j].data[i]) === 'object') {
  51. tdBodys += '<td>' + series[j].data[i].value + '</td>'
  52. } else {
  53. tdBodys += '<td>' + series[j].data[i] + '</td>'
  54. }
  55. }
  56. table += '<tr><td style="padding: 0 10px">' + axisData[i] + '</td>' + tdBodys + '</tr>'
  57. tdBodys = ''
  58. }
  59. table += '</tbody></table>'
  60. return table
  61. }
  62. },
  63. // magicType: { show: true, type: ['line', 'bar'] },
  64. // restore: { show: true },
  65. saveAsImage: { show: true }
  66. },
  67. iconStyle: {
  68. borderColor: 'white'
  69. }
  70. },
  71. legend: {
  72. orient: 'vertical',
  73. left: 'center',
  74. bottom: 'bottom',
  75. data: [],
  76. textStyle: {
  77. color: '#ffff',
  78. fontSize: 12
  79. }
  80. },
  81. xAxis: [
  82. {
  83. type: 'category',
  84. data: [],
  85. axisPointer: {
  86. type: 'shadow'
  87. }
  88. }
  89. ],
  90. yAxis: [
  91. {
  92. type: 'value',
  93. name: '个数',
  94. min: 0,
  95. // max: 100,
  96. // interval: 20,
  97. axisLabel: {
  98. formatter: '{value}'
  99. }
  100. },
  101. {
  102. type: 'value',
  103. name: '百分比',
  104. min: 0,
  105. max: 100,
  106. // interval: 20,
  107. axisLabel: {
  108. formatter: '{value} %'
  109. }
  110. }
  111. ],
  112. series: [
  113. {
  114. barMaxWidth: 30,
  115. name: '',
  116. type: 'bar',
  117. tooltip: {
  118. valueFormatter: function (value) {
  119. return value
  120. }
  121. },
  122. data: []
  123. },
  124. {
  125. barMaxWidth: 30,
  126. name: '',
  127. type: 'bar',
  128. tooltip: {
  129. valueFormatter: function (value) {
  130. return value
  131. }
  132. },
  133. data: []
  134. },
  135. {
  136. barMaxWidth: 30,
  137. name: '',
  138. type: 'bar',
  139. tooltip: {
  140. valueFormatter: function (value) {
  141. return value
  142. }
  143. },
  144. data: []
  145. },
  146. {
  147. barMaxWidth: 30,
  148. name: '',
  149. type: 'bar',
  150. tooltip: {
  151. valueFormatter: function (value) {
  152. return value
  153. }
  154. },
  155. data: []
  156. },
  157. {
  158. barMaxWidth: 30,
  159. name: '',
  160. type: 'line',
  161. yAxisIndex: 1,
  162. tooltip: {
  163. valueFormatter: function (value) {
  164. return value + ' %'
  165. }
  166. },
  167. data: []
  168. },
  169. {
  170. barMaxWidth: 30,
  171. name: '',
  172. type: 'line',
  173. yAxisIndex: 1,
  174. tooltip: {
  175. valueFormatter: function (value) {
  176. return value + ' %'
  177. }
  178. },
  179. data: []
  180. },
  181. {
  182. barMaxWidth: 30,
  183. name: '',
  184. type: 'line',
  185. yAxisIndex: 1,
  186. tooltip: {
  187. valueFormatter: function (value) {
  188. return value + ' %'
  189. }
  190. },
  191. data: []
  192. }
  193. ]
  194. }
  195. }
  196. },
  197. watch: {
  198. info: {
  199. handler (newVal, oldVal) {
  200. this.getMiddleLeft()
  201. },
  202. deep: true
  203. }
  204. },
  205. mounted () {
  206. const this_ = this
  207. this.$nextTick(() => {
  208. this_.getMiddleLeft()
  209. })
  210. },
  211. methods: {
  212. getMiddleLeft () {
  213. this.option.xAxis[0].data = this.info.yearArr
  214. this.option.legend.data = ['国家级开展数', '国家级参加数', '省级开展数', '省级参加数', '国家级参加率', '省级参加率', '总参加率']
  215. this.option.series[0].name = '国家级开展数'
  216. this.option.series[1].name = '国家级参加数'
  217. this.option.series[2].name = '省级开展数'
  218. this.option.series[3].name = '省级参加数'
  219. this.option.series[4].name = '国家级参加率'
  220. this.option.series[5].name = '省级参加率'
  221. this.option.series[6].name = '总参加率'
  222. this.option.series[0].data = this.info.list1
  223. this.option.series[1].data = this.info.list2
  224. this.option.series[2].data = this.info.list3
  225. this.option.series[3].data = this.info.list4
  226. this.option.series[4].data = this.info.list5
  227. this.option.series[5].data = this.info.list6
  228. this.option.series[6].data = this.info.list7
  229. // this.option.series[2].data = [1, 1, 1, 1, 1]
  230. const chartDom = document.getElementById(this.info.id)
  231. var myChart = echarts.init(chartDom)
  232. setTimeout(() => {
  233. myChart.setOption(this.option)
  234. }, 2000)
  235. }
  236. }
  237. }
  238. </script>
  239. <style lang="scss" scoped>
  240. .pieView {
  241. width: 100%;
  242. height: 100%;
  243. overflow: hidden;
  244. background-color: rgba(6, 30, 93, 0.5);
  245. }
  246. </style>