PopulationStructure.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div id="populationStructure">
  3. <div id="pop"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import echarts from 'echarts'
  8. export default {
  9. name: 'populationStructure',
  10. components: {
  11. },
  12. data() {
  13. return {
  14. }
  15. },
  16. mounted() {
  17. this.init()
  18. },
  19. methods: {
  20. init(){
  21. var myChart = echarts.init(document.getElementById('pop'));
  22. var xData = ["18以下", "18-60","60-80","80以上"];
  23. var yData = [50, 87.3,30,70];
  24. var shadowYData=[100,100];
  25. var color="#19dfdd";
  26. var shadowColor="#0b5767";
  27. var barWidth=50;
  28. var option = {
  29. // backgroundColor: '#05233b',
  30. "grid": {
  31. "top": "25%",
  32. "left": "-5%",
  33. "bottom": "5%",
  34. "right": "5%",
  35. "containLabel": true
  36. },
  37. animation: false,
  38. "xAxis": [{
  39. "type": "category",
  40. "data": xData,
  41. "axisTick": {
  42. "alignWithLabel": true
  43. },
  44. "nameTextStyle": {
  45. "color": "#82b0ec"
  46. },
  47. "axisLine": {
  48. show: false,
  49. "lineStyle": {
  50. "color": "#82b0ec"
  51. }
  52. },
  53. "axisLabel": {
  54. "textStyle": {
  55. "color": color
  56. },
  57. margin: 30
  58. }
  59. }],
  60. "yAxis": [{
  61. show: false,
  62. "type": "value",
  63. "axisLabel": {
  64. "textStyle": {
  65. "color": "#fff"
  66. },
  67. },
  68. "splitLine": {
  69. "lineStyle": {
  70. "color": "#0c2c5a"
  71. }
  72. },
  73. "axisLine": {
  74. "show": false
  75. }
  76. }],
  77. "series": [
  78. {
  79. "name": "数据上椭圆",
  80. type: 'pictorialBar',
  81. symbolSize: [barWidth, 10],
  82. symbolOffset: [0, -6],
  83. symbolPosition: 'end',
  84. z: 12,
  85. "label": {
  86. "normal": {
  87. "show": true,
  88. "position": "top",
  89. fontSize: 14,
  90. color: color,
  91. formatter:function(params,index){
  92. return params.value+"%";
  93. }
  94. }
  95. },
  96. color: "#2DB1EF",
  97. data: yData
  98. },
  99. {
  100. name: '',
  101. type: 'pictorialBar',
  102. symbolSize: [barWidth, 10],
  103. symbolOffset: [0, 7],
  104. z: 12,
  105. "color": color,
  106. "data": yData
  107. },
  108. {
  109. name: '',
  110. type: 'pictorialBar',
  111. symbolSize: [barWidth+5, 15],
  112. symbolOffset: [0, 12],
  113. z: 10,
  114. itemStyle: {
  115. normal: {
  116. color: 'transparent',
  117. borderColor: color,
  118. borderType: 'solid',
  119. borderWidth: 1
  120. }
  121. },
  122. data: yData
  123. },
  124. {
  125. name: '',
  126. type: 'pictorialBar',
  127. symbolSize: [barWidth+10, 20],
  128. symbolOffset: [0, 18],
  129. z: 10,
  130. itemStyle: {
  131. normal: {
  132. color: 'transparent',
  133. borderColor: color,
  134. borderType: 'solid',
  135. borderWidth: 2
  136. }
  137. },
  138. data: yData
  139. },
  140. {
  141. type: 'bar',
  142. "barWidth": barWidth,
  143. barGap: '10%', // Make series be overlap
  144. barCateGoryGap: '10%',
  145. itemStyle: {
  146. normal: {
  147. color: new echarts.graphic.LinearGradient(0, 0, 0, 0.7, [{
  148. offset: 0,
  149. color: "rgba(25,223,221,.7)"
  150. },
  151. {
  152. offset: 1,
  153. color: "rgba(25,223,221,.3)"
  154. }
  155. ]),
  156. },
  157. },
  158. data: yData
  159. },
  160. {
  161. "name": "阴影椭圆",
  162. type: 'pictorialBar',
  163. symbolSize: [barWidth, 10],
  164. symbolOffset: [0, -6],
  165. symbolPosition: 'end',
  166. z: 12,
  167. "label": {
  168. "show": false,
  169. },
  170. color: shadowColor,
  171. data: shadowYData
  172. },
  173. {
  174. name:"阴影柱体",
  175. type: 'bar',
  176. "barWidth": barWidth,
  177. barCateGoryGap: '10%',
  178. "zlevel": -1,
  179. "barGap": "-100%",
  180. itemStyle: {
  181. color: shadowColor
  182. },
  183. data: shadowYData
  184. },
  185. ]
  186. };
  187. // 使用刚指定的配置项和数据显示图表。
  188. myChart.setOption(option);
  189. }
  190. }
  191. }
  192. </script>
  193. <style scoped>
  194. #populationStructure{
  195. position: absolute;
  196. width: 100%;
  197. height: 25%;
  198. z-index: 2;
  199. top:75%;
  200. }
  201. #pop{
  202. position: absolute;
  203. width: 100%;
  204. height: 100%;
  205. /* background-color: rgb(0, 0, 255,0.4); */
  206. }
  207. </style>