chart-keyArea.vue 7.6 KB

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