wpjg.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <div class="wpjg">
  3. <div class="box">
  4. <div id="wpjp_echart">
  5. </div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  11. export default {
  12. components: {},
  13. data() {
  14. return {};
  15. },
  16. //监听属性 类似于data概念
  17. computed: {},
  18. //监控data中的数据变化
  19. watch: {},
  20. beforeCreate() { }, //生命周期 - 创建之前
  21. created() { }, //生命周期 - 创建完成(可以访问当前this实例)
  22. beforeMount() { }, //生命周期 - 挂载之前
  23. methods: {
  24. getRenKou() {
  25. var dom = document.getElementById('wpjp_echart');
  26. var myChart = window.echarts.init(dom);
  27. let data = [
  28. { name: '疑似新增建设', value: 30 },
  29. { name: '耕地变化', value: 40 },
  30. { name: '建设和设施农用地变化', value: 50 },
  31. { name: '非耕农用地变化', value: 24 },
  32. { name: '耕地变化', value: 24 },
  33. { name: '新增围填海', value: 24 },
  34. ]
  35. for (var i = 0; i < data.length; i++) {
  36. for (var j = i + 1; j < data.length; j++) {
  37. //如果第一个比第二个大,就交换他们两个位置
  38. if (data[i].value < data[j].value) {
  39. var temp = data[i];
  40. data[i] = data[j];
  41. data[j] = temp;
  42. }
  43. }
  44. }
  45. let pm = []
  46. for (var i = 0; i < data.length; i++) {
  47. let k = i + 1
  48. pm.push('NO.' + k)
  49. }
  50. data.forEach(function (value, index, obj) {
  51. value.pm = pm[index]
  52. })
  53. console.log('ssss', data)
  54. const colors = ['rgb(96,149,239)', 'rgb(239,157,147)', 'rgb(232,191,72)', 'rgb(189,147,227)']
  55. const chartData = data.map((item, index) => ({
  56. value: item.value,
  57. name: item.name,
  58. pm: item.pm,
  59. itemStyle: {
  60. shadowBlur: 20,
  61. shadowColor: `#${(((index + 1) % 7) + 10) * 100 + 99}`,
  62. shadowOffsetx: 25,
  63. shadowOffsety: 20,
  64. color: colors[index % colors.length],
  65. },
  66. }))
  67. const sum = chartData.reduce((per, cur) => per + cur.value, 0)
  68. const gap = (1 * sum) / 100
  69. const pieData1 = []
  70. const gapData = {
  71. name: '',
  72. value: gap,
  73. itemStyle: {
  74. color: 'transparent',
  75. },
  76. }
  77. let totalRatio = []
  78. // let totalPercent = 0
  79. for (let i = 0; i < chartData.length; i++) {
  80. // 计算占比
  81. // let ratio = (chartData[i].value / sum).toFixed(2) * 100;
  82. // 累加占比到总占比中
  83. // totalRatio.push(ratio*100)
  84. let ratio = (chartData[i].value / sum) * 100
  85. let percent = Math.round(ratio)
  86. totalRatio.push(percent)
  87. // totalPercent += percent
  88. // 第一圈数据
  89. pieData1.push({
  90. ...chartData[i],
  91. })
  92. pieData1.push(gapData)
  93. }
  94. // 补充最后一项占比百分比保证之和为100%
  95. // totalRatio[0].value += 100 - totalPercent
  96. let option = {
  97. backgroundColor: 'rgba(1,1,1,0)',
  98. title: {
  99. show: true,
  100. // text: sum
  101. text: '变化类型',
  102. x: '49%',
  103. y: '32%',
  104. itemGap: 6,
  105. textStyle: {
  106. color: '#fff',
  107. fontSize: 11,
  108. fontWeight: '400',
  109. lineHeight: 8,
  110. },
  111. subtextStyle: {
  112. color: '#fff',
  113. fontSize: 8,
  114. fontWeight: '400',
  115. lineHeight: 8,
  116. },
  117. textAlign: 'center',
  118. },
  119. // 图例
  120. legend: {
  121. show: true,
  122. orient: 'vertical',
  123. icon: 'rect',
  124. textStyle: {
  125. color: '#fff',
  126. fontSize: 10,
  127. },
  128. top: '5%',
  129. left: '70%',
  130. itemGap: 14,
  131. itemHeight: 14,
  132. itemWidth: 14,
  133. data: chartData,
  134. formatter: function (name) {
  135. const selectedItem = chartData.find((item) => `${item.name}`.includes(`${name}`));
  136. // if (selectedItem) {
  137. // const { value } = selectedItem;
  138. // const { pm } = selectedItem;
  139. // console.log('dddd', selectedItem)
  140. // const p = ((value / sum) * 100).toFixed(2);
  141. // const area = `${value}m²`;
  142. // // console.log(`{icon|${pm}} {name|${name}} {percent|${p}%} {area|${area}} `);
  143. // return `{icon|${pm}} {name|${name}} {percent|${p}%} {area|${area}} `;
  144. // } else {
  145. // console.log(name);
  146. // return name;
  147. // }
  148. if (selectedItem) {
  149. console.log();
  150. return name + selectedItem.value + "个";
  151. }
  152. },
  153. },
  154. series: [
  155. // 中间圆环
  156. {
  157. name: '',
  158. type: 'pie',
  159. roundCap: true,
  160. radius: ['36%', '52%'],
  161. center: ['50%', '35%'],
  162. data: pieData1,
  163. labelLine: {
  164. length: 8,
  165. length2: 16,
  166. lineStyle: {
  167. width: 1,
  168. },
  169. },
  170. label: {
  171. show: false,
  172. fontFamily: 'ysbth',
  173. position: 'outside',
  174. padding: [0, -4, 0, -4],
  175. formatter(params) {
  176. if (params.name === '') {
  177. return ''
  178. }
  179. return `${params.percent.toFixed(0)}% `
  180. },
  181. color: '#fff',
  182. fontSize: '14px',
  183. lineHeight: 10,
  184. },
  185. emphasis: {
  186. // 鼠标移入时显示
  187. label: {
  188. show: true,
  189. },
  190. },
  191. },
  192. // 最里面圆环
  193. {
  194. type: 'pie',
  195. radius: ['28%', '30%'],
  196. center: ['50%', '35%'],
  197. animation: false,
  198. hoverAnimation: false,
  199. data: [
  200. {
  201. value: 100,
  202. },
  203. ],
  204. label: {
  205. show: false,
  206. },
  207. itemStyle: {
  208. color: '#3BC5EF',
  209. },
  210. },
  211. // 最里面圆环内的背景圆
  212. {
  213. name: '',
  214. type: 'pie',
  215. startAngle: 90,
  216. radius: '28%',
  217. animation: false,
  218. hoverAnimation: false,
  219. center: ['50%', '35%'],
  220. itemStyle: {
  221. labelLine: {
  222. show: false,
  223. },
  224. color: {
  225. type: 'radial',
  226. x: 0.5,
  227. y: 0.5,
  228. r: 1,
  229. colorStops: [
  230. {
  231. offset: 1,
  232. color: 'rgba(50,171,241, 0)',
  233. },
  234. {
  235. offset: 0.5,
  236. color: 'rgba(50,171,241, .4)',
  237. },
  238. {
  239. offset: 0,
  240. color: 'rgba(55,70,130, 0)',
  241. },
  242. ],
  243. global: false, // 缺省为 false
  244. },
  245. shadowBlur: 60,
  246. },
  247. data: [
  248. {
  249. value: 100,
  250. },
  251. ],
  252. },
  253. // 最外面的圆环
  254. {
  255. type: 'pie',
  256. color: ['#1a4a8c', 'rgba(0,0,0,0)', '#1a4a8c', 'rgba(0,0,0,0)'],
  257. radius: ['53%', '54%'],
  258. center: ['50%', '35%'],
  259. label: {
  260. show: false,
  261. },
  262. select: {
  263. display: false,
  264. },
  265. tooltip: {
  266. show: false,
  267. },
  268. data: totalRatio,
  269. },
  270. ],
  271. }
  272. myChart.setOption(option);
  273. },
  274. },
  275. mounted() {
  276. this.getRenKou();
  277. },
  278. beforeUpdate() { }, //生命周期 - 更新之前
  279. updated() { }, //生命周期 - 更新之后
  280. beforeDestroy() { }, //生命周期 - 销毁之前
  281. destroy() { },//生命周期 - 销毁完成
  282. activated() { }, //若组件实例是 <KeepAlive> 缓存树的一部分,当组件被插入到 DOM 中时调用。
  283. deactivated() { } //若组件实例是 <KeepAlive> 缓存树的一部分,当组件从 DOM 中被移除时调用。
  284. };
  285. </script>
  286. <style lang="scss" scoped>
  287. .wpjg {
  288. border-width: 0px;
  289. position: absolute;
  290. left: 1366px;
  291. top: 68%;
  292. display: -ms-flexbox;
  293. display: flex;
  294. .box {
  295. font-family: 'Arial Normal', 'Arial';
  296. font-weight: 400;
  297. font-style: normal;
  298. font-size: 13px;
  299. letter-spacing: normal;
  300. color: #333333;
  301. text-align: center;
  302. line-height: normal;
  303. text-transform: none;
  304. border-width: 0px;
  305. position: absolute;
  306. left: 0px;
  307. top: 0px;
  308. width: 535px;
  309. height: 260px;
  310. background: inherit;
  311. background-color: rgba(3, 25, 67, 0.698039215686274);
  312. border: none;
  313. border-radius: 0px;
  314. box-shadow: none;
  315. background-repeat: no-repeat;
  316. background-size: 100% 47%;
  317. background-image: url("/static/images/cockpitNew/wpjg.png");
  318. #wpjp_echart {
  319. width: 580px;
  320. height: 230px;
  321. position: relative;
  322. left: -28%;
  323. top: 40%;
  324. }
  325. }
  326. }
  327. </style>