chart-freelyraise.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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(data) {
  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.value).toFixed(0);
  123. attaName[index] = it.name;
  124. topName[index] = `${it.name}`
  125. });
  126. var salvProMax = [];
  127. var max = attaData[0];
  128. for (let i = 0; i < attaData.length; i++) {
  129. max = max < attaData[i + 1] ? attaData[i + 1] : max;
  130. }
  131. for (let i = 0; i < attaData.length; i++) {
  132. salvProMax.push(max); //背景按最大值
  133. }
  134. function attackSourcesDataFmt(sData) {
  135. var sss = [];
  136. sData.forEach(function(item, i) {
  137. let itemStyle = {
  138. color: i > 5 ? attackSourcesColor[5] : attackSourcesColor[i]
  139. };
  140. sss.push({
  141. value: item,
  142. itemStyle: itemStyle
  143. });
  144. });
  145. return sss;
  146. }
  147. option = {
  148. tooltip: {
  149. show: false,
  150. backgroundColor: "rgba(3,169,244, 0.5)", //背景颜色(此时为默认色)
  151. textStyle: {
  152. fontSize: 12
  153. }
  154. },
  155. color: ["#F7B731"],
  156. legend: {
  157. show: false,
  158. pageIconSize: [12, 12],
  159. itemWidth: 20,
  160. itemHeight: 10,
  161. textStyle: {
  162. //图例文字的样式
  163. fontSize: 12,
  164. color: "#fff"
  165. },
  166. selectedMode: false,
  167. data: ["个人所得(亿元)"]
  168. },
  169. grid: {
  170. left: '12%',
  171. width: '70%',
  172. bottom: '5%',
  173. top: "8%",
  174. },
  175. xAxis: {
  176. type: "value",
  177. splitLine: {
  178. show: false
  179. },
  180. axisLabel: {
  181. show: false
  182. },
  183. axisTick: {
  184. show: false
  185. },
  186. axisLine: {
  187. show: false
  188. }
  189. },
  190. yAxis: [{ //左侧排行数字
  191. type: "category",
  192. inverse: true,
  193. axisLine: {
  194. show: false
  195. },
  196. axisTick: {
  197. show: false
  198. },
  199. axisPointer: {
  200. label: {
  201. show: true,
  202. //margin: 30
  203. }
  204. },
  205. padding: [5, 0, 0, 0],
  206. postion: "right",
  207. data: attaName,
  208. axisLabel: {
  209. margin: 30,
  210. fontSize: 12,
  211. align: "left",
  212. padding: [2, 0, 0, 0],
  213. color: "#000",
  214. rich: {
  215. nt1: {
  216. color: "#fff",
  217. backgroundColor: attackSourcesColor1[0],
  218. width: 15,
  219. height: 15,
  220. fontSize: 12,
  221. align: "center",
  222. borderRadius: 100,
  223. lineHeight: "5",
  224. padding: [0, 1, 2, 1]
  225. // padding:[0,0,2,0],
  226. },
  227. nt2: {
  228. color: "#fff",
  229. backgroundColor: attackSourcesColor1[1],
  230. width: 15,
  231. height: 15,
  232. fontSize: 12,
  233. align: "center",
  234. borderRadius: 100,
  235. padding: [0, 1, 2, 1]
  236. },
  237. nt3: {
  238. color: "#fff",
  239. backgroundColor: attackSourcesColor1[2],
  240. width: 15,
  241. height: 15,
  242. fontSize: 12,
  243. align: "center",
  244. borderRadius: 100,
  245. padding: [0, 1, 2, 1]
  246. },
  247. nt: {
  248. color: "#fff",
  249. backgroundColor: attackSourcesColor1[3],
  250. width: 15,
  251. height: 15,
  252. fontSize: 12,
  253. align: "center",
  254. lineHeight: 3,
  255. borderRadius: 100,
  256. padding: [0, 1, 2, 1],
  257. lineHeight: 5
  258. }
  259. },
  260. }
  261. },
  262. { //右侧名字
  263. type: "category",
  264. inverse: true,
  265. axisTick: "none",
  266. axisLine: "none",
  267. show: true,
  268. axisLabel: {
  269. textStyle: {
  270. color: "#fff",
  271. fontSize: "12"
  272. }
  273. },
  274. //data: attackSourcesDataFmt(attaName)
  275. data: attackSourcesDataFmt(attaData) //数字
  276. },
  277. { //名称
  278. type: 'category',
  279. offset: -10,
  280. position: "left",
  281. axisLabel: {
  282. color: `#fff`,
  283. fontSize: 10
  284. },
  285. axisLine: {
  286. show: false
  287. },
  288. inverse: true,
  289. axisTick: {
  290. show: false
  291. },
  292. axisLabel: {
  293. interval: 0,
  294. color: ["#fff"],
  295. align: "left",
  296. verticalAlign: "bottom",
  297. lineHeight: 32,
  298. fontSize: 12
  299. },
  300. data: topName
  301. },
  302. ],
  303. series: [{ //条形图数值
  304. zlevel: 1,
  305. name: "个人所得(亿元)",
  306. type: "bar",
  307. barWidth: "8px",
  308. animationDuration: 1500,
  309. data: attackSourcesDataFmt(attaData),
  310. align: "center",
  311. itemStyle: {
  312. normal: {
  313. barBorderRadius: 10
  314. }
  315. },
  316. label: {
  317. show: false,
  318. fontSize: 12,
  319. color: "#fff",
  320. textBorderWidth: 2,
  321. padding: [2, 0, 0, 0]
  322. }
  323. },
  324. { //最大值背景条形图
  325. name: "个人所得(亿元)",
  326. type: "bar",
  327. barWidth: 8,
  328. barGap: "-100%",
  329. margin: "20",
  330. data: salvProMax,
  331. textStyle: {
  332. //图例文字的样式
  333. fontSize: 12,
  334. color: "#fff"
  335. },
  336. itemStyle: {
  337. normal: {
  338. color: "#05325F",
  339. //width:"100%",
  340. fontSize: 12,
  341. barBorderRadius: 30
  342. },
  343. }
  344. }
  345. ]
  346. };
  347. option && myChart.setOption(option);
  348. },
  349. },
  350. }
  351. </script>
  352. <style rel="stylesheet/scss" lang="scss" scoped>
  353. .chart-container {
  354. width: 100%;
  355. height: auto;
  356. position: relative;
  357. padding-bottom: 10px;
  358. display: flex;
  359. }
  360. </style>