80056937bd02f2a3ea0dc4c9ad0be25f4782a0b5.svn-base 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!-- -->
  2. <template>
  3. <div style="width:100%;height:100%;">
  4. <div class="simple_header">
  5. <div class="simple_header_icon"></div>
  6. <div class="simple_header_text">{{mapTitleFocusName +"数量分布"}}</div>
  7. </div>
  8. <div class="" style="width: 100%;" :style="{'height':heightCont +'px'}">
  9. <div style="width:100%;height:100%;" id="barChart" ref="barChart"></div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  15. //例如:import 《组件名称》 from '《组件路径》';
  16. import echarts from 'echarts'
  17. export default {
  18. //import引入的组件需要注入到对象中才能使用
  19. props:['mapTitleFocusName','barData','barStartColor','barEndColor','barsChooseUnit'],
  20. components: {},
  21. data() {
  22. //这里存放数据
  23. return {
  24. xData:[],
  25. yData:[],
  26. themeColor:'rgba(93, 104, 118, 1)',
  27. themeColorSplitLine:'#888ea3'
  28. };
  29. },
  30. //监听属性 类似于data概念
  31. computed: {
  32. msg(){
  33. return this.$store.state.theme.testMsg;
  34. },
  35. heightCont(){
  36. if(window.innerWidth <= 1366){
  37. return window.innerHeight *0.17;
  38. }else{
  39. return window.innerHeight *0.15;
  40. }
  41. }
  42. },
  43. //监控data中的数据变化
  44. watch: {
  45. barData(newValue,oldValue){
  46. this.initIncChart();
  47. },
  48. msg(n,o){
  49. if( n == 'dark'){
  50. this.themeColor = 'rgba(177, 210, 254, 1)';
  51. this.themeColorSplitLine = 'rgba(177, 210, 254, 1)';
  52. this.initIncChart();
  53. }else{
  54. this.themeColor = 'rgba(93, 104, 118, 1)';
  55. this.themeColorSplitLine = 'rgba(177, 210, 254, 1)';
  56. this.initIncChart();
  57. }
  58. }
  59. },
  60. //方法集合
  61. methods: {
  62. initIncChart:function(){
  63. var _self = this;
  64. _self.barData.forEach(element => {
  65. if(element.name){
  66. _self.xData.push(element.name.replace(/\省|\市|\自治区|\维吾尔自治区|\生产建设|\壮族|\回族/ig, ''));
  67. _self.yData.push(element.total);
  68. }
  69. });
  70. let chart = echarts.init(this.$refs['barChart']);
  71. let option = {
  72. // backgroundColor:'rgba(226,250,255,1)',
  73. grid:{
  74. top:'3%',
  75. bottom:'3%',
  76. left:'3%',
  77. right:'3%',
  78. containLabel:true
  79. },
  80. tooltip: {
  81. trigger: 'axis',
  82. label: {
  83. show: true
  84. },
  85. formatter: function (params) {
  86. return params[0].axisValue + ': ' +params[0].data + _self.barsChooseUnit
  87. }
  88. },
  89. xAxis: {
  90. axisLabel:{
  91. rotate:30,
  92. color:_self.themeColor
  93. },
  94. axisLine: {
  95. show: false,
  96. },
  97. splitLine: {
  98. show: false
  99. },
  100. axisTick: {
  101. show: false,
  102. alignWithLabel: true
  103. },
  104. type: 'category',
  105. data: _self.xData
  106. },
  107. yAxis: {
  108. axisLabel:{
  109. color:_self.themeColor
  110. },
  111. axisLine: {
  112. show: false,
  113. },
  114. splitLine: {
  115. show: true,
  116. lineStyle: {
  117. type: 'dashed',
  118. color: _self.themeColorSplitLine
  119. }
  120. },
  121. axisTick: {
  122. show: false
  123. },
  124. splitArea: {
  125. show: true,
  126. areaStyle: {
  127. color: 'transparent'//浅色主题
  128. // color: ["rgba(250,250,250,0.0)", "rgba(250,250,250,0.05)"]
  129. }
  130. },
  131. type: 'value',
  132. max: function(value) {
  133. return value.max + 1;
  134. },
  135. min: function(value) {
  136. return 0;
  137. },
  138. },
  139. series: [{
  140. barMaxWidth: '30%',
  141. symbolSize: 7,
  142. lineStyle: {
  143. color: 'rgba(124, 129, 255, 1)',
  144. shadowBlur: 12,
  145. shadowColor: 'rgba(33,148,246,0.9)',
  146. shadowOffsetX: 1,
  147. shadowOffsetY: 1
  148. },
  149. itemStyle: {
  150. borderWidth: 1,
  151. color: 'rgba(124, 129, 255, 1)',
  152. borderColor: 'rgba(124, 129, 255, 1)',
  153. normal: {
  154. barBorderRadius:[5,5,0,0],
  155. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  156. offset: 0,
  157. color: this.barStartColor
  158. },
  159. {
  160. offset: 1,
  161. color: this.barEndColor
  162. }
  163. ])
  164. },
  165. },
  166. data: _self.yData,
  167. type: 'bar',
  168. areaStyle: {
  169. // color: 'rgba(63, 158, 255, 0.3)',
  170. normal: {
  171. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  172. offset: 0,
  173. color: "rgba(63, 158, 255, 0.6)"
  174. },
  175. {
  176. offset: 1,
  177. color: "rgba(63, 158, 255, 0.3)"
  178. }
  179. ])
  180. }
  181. }
  182. }]
  183. };
  184. chart.setOption(option);
  185. this.xData = [];
  186. this.yData = [];
  187. },
  188. },
  189. //生命周期 - 创建完成(可以访问当前this实例)
  190. created() {
  191. },
  192. //生命周期 - 挂载完成(可以访问DOM元素)
  193. mounted() {
  194. },
  195. beforeCreate() {}, //生命周期 - 创建之前
  196. beforeMount() {}, //生命周期 - 挂载之前
  197. beforeUpdate() {}, //生命周期 - 更新之前
  198. updated() {}, //生命周期 - 更新之后
  199. beforeDestroy() {}, //生命周期 - 销毁之前
  200. destroyed() {}, //生命周期 - 销毁完成
  201. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  202. }
  203. </script>
  204. <style scoped>
  205. </style>