c396dc37c0f079dd60148dc080e3037cf7d2b826.svn-base 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <!-- 督查对象完成情况饼图
  2. 通过props接收外部传值来更新饼图
  3. -->
  4. <template>
  5. <div style="width:100%;height:100%;">
  6. <div class="simple_header">
  7. <div class="simple_header_icon"></div>
  8. <div class="simple_header_text">督查对象</div>
  9. </div>
  10. <div class="right_FinishRate_content" >
  11. <div style="width:100%;height:100%;" ref="finishratechart" id="finishratechart"></div>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. //这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  17. //例如:import 《组件名称》 from '《组件路径》';
  18. import echarts from 'echarts'
  19. // import theme from '../../store/theme'
  20. export default {
  21. //import引入的组件需要注入到对象中才能使用
  22. components: {},
  23. props:['finishNumber','unfinishNumber'],
  24. data() {
  25. //这里存放数据
  26. return {
  27. viewHeight:window.innerHeight,
  28. viewWidth:window.innerWidth,
  29. itemWidthChart:25,
  30. itemHeightChart:14,
  31. topChart:'',
  32. pcOrPadFontSize:12,
  33. themeColor:'#333',
  34. finishNumberNew: null,
  35. unfinishNumberNew: null
  36. };
  37. },
  38. //监听属性 类似于data概念
  39. computed: {
  40. msg(){
  41. // return theme.state.testMsg;
  42. return this.$store.state.theme.testMsg;
  43. },
  44. },
  45. //监控data中的数据变化
  46. watch: {
  47. finishNumberNew:function(){
  48. if( (typeof this.finishNumberNew) == 'number'){
  49. this.initChart();
  50. }else{
  51. this.finishNumberNew = 85;
  52. }
  53. },
  54. unfinishNumberNew:function(){
  55. if( (typeof this.unfinishNumberNew) == 'number'){
  56. this.initChart();
  57. }else{
  58. this.unfinishNumberNew = 15;
  59. }
  60. },
  61. msg(n,o){
  62. if( n == 'dark'){
  63. this.themeColor = 'rgba(177, 210, 254, 1)';
  64. this.initChart();
  65. }else{
  66. this.themeColor = '#333';
  67. this.initChart();
  68. }
  69. }
  70. },
  71. //方法集合
  72. methods: {
  73. updateFinishRateDataAndChart:function(){
  74. // 制作方法调用以更新数据与图表。使用方法调用可以显式控制更新数据的先后顺序。
  75. },
  76. initChart:function(){
  77. let _self = this;
  78. let chart = echarts.init(this.$refs['finishratechart']);
  79. let option = {
  80. backgroundColor:'rgba(0,0,0,0)',
  81. color:['#5CE9C7','#FEB23A'],
  82. title: {
  83. text: '',
  84. left: 'center',
  85. top: 20,
  86. textStyle: {
  87. color: '#ccc'
  88. }
  89. },
  90. legend: {
  91. textStyle:{
  92. fontSize:this.pcOrPadFontSize,
  93. color:this.themeColor
  94. },
  95. itemWidth: this.itemWidthChart, // 设置宽度
  96. itemHeight: this.itemHeightChart, // 设置高度
  97. top:this.topChart,
  98. x : 'center',
  99. y : 'bottom',
  100. data:['已督查','未督查','完成率'],
  101. icon:'circle',
  102. formatter: function (name) {
  103. if(name=='已督查'){
  104. return '' + name+':'+_self.finishNumberNew;
  105. }else if(name=='未督查'){
  106. return '' + name+':'+_self.unfinishNumberNew;
  107. }else{
  108. return '' + name+':balabala%';
  109. }
  110. }
  111. },
  112. tooltip : {
  113. trigger: 'item',
  114. formatter: "{a} <br/>{b} : {c} ({d}%)"
  115. },
  116. series : [
  117. {
  118. name:'督查对象',
  119. type:'pie',
  120. radius : '60%',
  121. center: ['50%', '40%'],
  122. data:[
  123. {
  124. value:_self.finishNumberNew, name:'已督查',
  125. // itemStyle: {
  126. // normal: {
  127. // shadowBlur: 20,
  128. // shadowColor: '#5CE9C7'
  129. // }
  130. // }
  131. },
  132. {
  133. value:_self.unfinishNumberNew, name:'未督查',
  134. // itemStyle: {
  135. // normal: {
  136. // shadowBlur: 20,
  137. // shadowColor: '#0195F2'
  138. // }
  139. // }
  140. },
  141. ],
  142. label: {
  143. normal: {
  144. show:false,
  145. textStyle: {
  146. color: 'rgba(255, 255, 255, 0.3)'
  147. }
  148. }
  149. },
  150. labelLine: {
  151. normal: {
  152. lineStyle: {
  153. color: 'rgba(255, 255, 255, 0.3)'
  154. },
  155. smooth: 0.2,
  156. length: 10,
  157. length2: 20
  158. }
  159. },
  160. animationType:'expansion'
  161. }
  162. ],
  163. animationDuration: '400',
  164. animationDurationUpdate:'400',
  165. animationEasing: 'cubicOut',
  166. animationEasingUpdate: 'cubicOut',
  167. };
  168. chart.setOption(option,true);
  169. }
  170. },
  171. //生命周期 - 创建完成(可以访问当前this实例)
  172. created() {},
  173. //生命周期 - 挂载完成(可以访问DOM元素)
  174. mounted(){
  175. this.finishNumberNew = this.finishNumber
  176. this.unfinishNumberNew = this.unfinishNumber
  177. if(this.viewWidth >= 1920){
  178. this.itemWidthChart = 25;
  179. this.itemHeightChart = 14;
  180. this.topChart = '85%';
  181. }else if(this.viewWidth <= 1024){
  182. this.itemWidthChart = 5;
  183. this.itemHeightChart = 5;
  184. this.topChart = '85%';
  185. this.pcOrPadFontSize = 8;
  186. }else if(this.viewWidth <= 1360){
  187. this.itemWidthChart = 5;
  188. this.itemHeightChart = 5;
  189. this.topChart = '75%';
  190. this.pcOrPadFontSize = 10;
  191. }else{
  192. this.itemWidthChart = 10;
  193. this.itemHeightChart = 10;
  194. this.topChart = '75%';
  195. }
  196. if(!this.finishNumberNew){
  197. this.finishNumberNew = 85;
  198. }
  199. if(!this.unfinishNumberNew){
  200. this.unfinishNumberNew = 15;
  201. }
  202. this.initChart();
  203. },
  204. beforeCreate() {}, //生命周期 - 创建之前
  205. beforeMount() {}, //生命周期 - 挂载之前
  206. beforeUpdate() {}, //生命周期 - 更新之前
  207. updated() {}, //生命周期 - 更新之后
  208. beforeDestroy() {}, //生命周期 - 销毁之前
  209. destroyed() {}, //生命周期 - 销毁完成
  210. activated() {} //如果页面有keep-alive缓存功能,这个函数会触发
  211. };
  212. </script>
  213. <style lang="scss" scoped>
  214. @media screen and (min-width: 960px) {
  215. @import "@scss/homeForPad";
  216. }
  217. // @media screen and (min-width: 1024px) {
  218. // @import "@scss/home1024";
  219. // }
  220. @media screen and (min-width: 1024px) and (max-width:1920px){
  221. @import "@scss/home";
  222. }
  223. @media screen and (min-width: 1920px) {
  224. @import "@scss/home1920";
  225. }
  226. </style>