chart-keyArea.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <!-- **************************************NO.7 散养户分布*************************************** -->
  2. <template>
  3. <div class="chart-container">
  4. <div id="freelyraise" style="width: 100%; height:23vh;">
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import * as echarts from 'echarts';
  10. import {getZdqy} from '@/api/bigdata'
  11. export default {
  12. name: 'freelyraise',
  13. data() {
  14. return {
  15. count: 0,
  16. data_zdqy: []
  17. }
  18. },
  19. mounted() {
  20. this.zdqy()
  21. },
  22. methods: {
  23. zdqy() {
  24. let that = this
  25. getZdqy().then(resp => {
  26. that.data_zdqy = resp.data
  27. that.myEcharts()
  28. })
  29. },
  30. // 出处 http://192.144.199.210/forum.php?mod=viewthread&tid=6785&highlight=%E6%9F%B1%E7%8A%B6%E5%9B%BE
  31. myEcharts() {
  32. let that = this
  33. var chartDom = document.getElementById('freelyraise');
  34. var myChart = echarts.init(chartDom);
  35. var color = ['#02CDFF', '#62FBE7', '#7930FF', '#ef5f9d', '#ecb935'];
  36. var option;
  37. let data = that.data_zdqy
  38. function contains(arr, dst) {
  39. var i = arr.length;
  40. while ((i -= 1)) {
  41. if (arr[i] == dst) {
  42. return i;
  43. }
  44. }
  45. return false;
  46. }
  47. var attackSourcesColor = [
  48. new echarts.graphic.LinearGradient(0, 1, 1, 1, [{
  49. offset: 0,
  50. color: "#EB3B5A"
  51. },
  52. {
  53. offset: 1,
  54. color: "#FE9C5A"
  55. }
  56. ]),
  57. new echarts.graphic.LinearGradient(0, 1, 1, 1, [{
  58. offset: 0,
  59. color: "#FA8231"
  60. },
  61. {
  62. offset: 1,
  63. color: "#FFD14C"
  64. }
  65. ]),
  66. new echarts.graphic.LinearGradient(0, 1, 1, 1, [{
  67. offset: 0,
  68. color: "#F7B731"
  69. },
  70. {
  71. offset: 1,
  72. color: "#FFEE96"
  73. }
  74. ]),
  75. new echarts.graphic.LinearGradient(0, 1, 1, 1, [{
  76. offset: 0,
  77. color: "#21fe8f"
  78. },
  79. {
  80. offset: 1,
  81. color: "#38911f"
  82. }
  83. ]),
  84. new echarts.graphic.LinearGradient(0, 1, 1, 1, [{
  85. offset: 0,
  86. color: "#395CFE"
  87. },
  88. {
  89. offset: 1,
  90. color: "#2EC7CF"
  91. }
  92. ])
  93. ];
  94. var attackSourcesColor1 = [
  95. "#EB3B5A",
  96. "#FA8231",
  97. "#F7B731",
  98. "#38911f",
  99. "#3860FC",
  100. "#F57474",
  101. "#56D0E3",
  102. "#1089E7",
  103. "#F57474",
  104. "#1089E7",
  105. "#F57474",
  106. "#F57474"
  107. ];
  108. var attaData = [];
  109. var attaName = [];
  110. var topName = []
  111. data.forEach((it, index) => {
  112. attaData[index] = parseFloat(it.num).toFixed(0);
  113. //attaData[index] = parseInt(it.num);
  114. attaName[index] = it.name;
  115. topName[index] = `${it.name}`
  116. });
  117. var salvProMax = [];
  118. var max = attaData[0];
  119. for (let i = 0; i < attaData.length; i++) {
  120. max = max < attaData[i + 1] ? attaData[i + 1] : max;
  121. }
  122. for (let i = 0; i < attaData.length; i++) {
  123. salvProMax.push(max); //背景按最大值
  124. }
  125. function attackSourcesDataFmt(sData) {
  126. var sss = [];
  127. sData.forEach(function (item, i) {
  128. let itemStyle = {
  129. color: i > 5 ? attackSourcesColor[5] : attackSourcesColor[i]
  130. };
  131. sss.push({
  132. value: item,
  133. itemStyle: itemStyle
  134. });
  135. });
  136. return sss;
  137. }
  138. option = {
  139. tooltip: {
  140. show: false,
  141. backgroundColor: "rgba(3,169,244, 0.5)", //背景颜色(此时为默认色)
  142. textStyle: {
  143. fontSize: 12
  144. }
  145. },
  146. color: ["#F7B731"],
  147. legend: {
  148. show: false,
  149. pageIconSize: [12, 12],
  150. itemWidth: 20,
  151. itemHeight: 10,
  152. textStyle: {
  153. //图例文字的样式
  154. fontSize: 12,
  155. color: "#fff"
  156. },
  157. selectedMode: false,
  158. data: ["个人所得(亿元)"]
  159. },
  160. grid: {
  161. left: '12%',
  162. width: '70%',
  163. bottom: '5%',
  164. top: "8%",
  165. },
  166. xAxis: {
  167. type: "value",
  168. splitLine: {
  169. show: false
  170. },
  171. axisLabel: {
  172. show: false
  173. },
  174. axisTick: {
  175. show: false
  176. },
  177. axisLine: {
  178. show: false
  179. }
  180. },
  181. yAxis: [{ //左侧排行数字
  182. type: "category",
  183. inverse: true,
  184. axisLine: {
  185. show: false
  186. },
  187. axisTick: {
  188. show: false
  189. },
  190. axisPointer: {
  191. label: {
  192. show: true,
  193. //margin: 30
  194. }
  195. },
  196. padding: [5, 0, 0, 0],
  197. postion: "right",
  198. data: attaName,
  199. axisLabel: {
  200. margin: 30,
  201. fontSize: 12,
  202. align: "left",
  203. padding: [2, 0, 0, 0],
  204. color: "#000",
  205. rich: {
  206. nt1: {
  207. color: "#fff",
  208. backgroundColor: attackSourcesColor1[0],
  209. width: 15,
  210. height: 15,
  211. fontSize: 12,
  212. align: "center",
  213. borderRadius: 100,
  214. lineHeight: "5",
  215. padding: [0, 1, 2, 1]
  216. // padding:[0,0,2,0],
  217. },
  218. nt2: {
  219. color: "#fff",
  220. backgroundColor: attackSourcesColor1[1],
  221. width: 15,
  222. height: 15,
  223. fontSize: 12,
  224. align: "center",
  225. borderRadius: 100,
  226. padding: [0, 1, 2, 1]
  227. },
  228. nt3: {
  229. color: "#fff",
  230. backgroundColor: attackSourcesColor1[2],
  231. width: 15,
  232. height: 15,
  233. fontSize: 12,
  234. align: "center",
  235. borderRadius: 100,
  236. padding: [0, 1, 2, 1]
  237. },
  238. nt: {
  239. color: "#fff",
  240. backgroundColor: attackSourcesColor1[3],
  241. width: 15,
  242. height: 15,
  243. fontSize: 12,
  244. align: "center",
  245. lineHeight: 3,
  246. borderRadius: 100,
  247. padding: [0, 1, 2, 1],
  248. lineHeight: 5
  249. }
  250. },
  251. }
  252. },
  253. { //右侧名字
  254. type: "category",
  255. inverse: true,
  256. axisTick: "none",
  257. axisLine: "none",
  258. show: true,
  259. axisLabel: {
  260. textStyle: {
  261. color: "#fff",
  262. fontSize: "12"
  263. }
  264. },
  265. //data: attackSourcesDataFmt(attaName)
  266. data: attackSourcesDataFmt(attaData) //数字
  267. },
  268. { //名称
  269. type: 'category',
  270. offset: -10,
  271. position: "left",
  272. axisLabel: {
  273. color: `#fff`,
  274. fontSize: 10
  275. },
  276. axisLine: {
  277. show: false
  278. },
  279. inverse: true,
  280. axisTick: {
  281. show: false
  282. },
  283. axisLabel: {
  284. interval: 0,
  285. color: ["#fff"],
  286. align: "left",
  287. verticalAlign: "bottom",
  288. lineHeight: 32,
  289. fontSize: 12
  290. },
  291. data: topName
  292. },
  293. ],
  294. series: [{ //条形图数值
  295. zlevel: 1,
  296. name: "个人所得(亿元)",
  297. type: "bar",
  298. barWidth: "8px",
  299. animationDuration: 1500,
  300. data: attackSourcesDataFmt(attaData),
  301. align: "center",
  302. itemStyle: {
  303. normal: {
  304. barBorderRadius: 10
  305. }
  306. },
  307. label: {
  308. show: false,
  309. fontSize: 12,
  310. color: "#fff",
  311. textBorderWidth: 2,
  312. padding: [2, 0, 0, 0]
  313. }
  314. },
  315. { //最大值背景条形图
  316. name: "个人所得(亿元)",
  317. type: "bar",
  318. barWidth: 8,
  319. barGap: "-100%",
  320. margin: "20",
  321. data: salvProMax,
  322. textStyle: {
  323. //图例文字的样式
  324. fontSize: 12,
  325. color: "#fff"
  326. },
  327. itemStyle: {
  328. normal: {
  329. color: "#05325F",
  330. //width:"100%",
  331. fontSize: 12,
  332. barBorderRadius: 30
  333. },
  334. }
  335. }
  336. ]
  337. };
  338. option && myChart.setOption(option);
  339. },
  340. },
  341. }
  342. </script>
  343. <style rel="stylesheet/scss" lang="scss" scoped>
  344. .chart-container {
  345. width: 100%;
  346. height: auto;
  347. position: relative;
  348. padding-bottom: 10px;
  349. display: flex;
  350. }
  351. </style>