gauge.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="">
  3. <!-- 签到人数 -->
  4. <view class="top-font">截至当前</view>
  5. <view class="signbox">
  6. <view class="sign-small-box">
  7. <view class="signNum">{{signinNum}}</view>
  8. <view class="bottom-font">签到人数</view>
  9. </view>
  10. <view class="sign-small-box">
  11. <view class="nosignNum">{{parseInt(totalCountNum)-parseInt(signinNum)}}</view>
  12. <view class="bottom-font">未签到人数</view>
  13. </view>
  14. </view>
  15. <!-- 仪表盘 -->
  16. <view class="qiun-charts3">
  17. <canvas canvas-id="canvasArcbar1" id="canvasArcbar1" class="charts3"></canvas>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import uCharts from '@/static/js/u-charts.js';
  23. var _self;
  24. var canvaArcbar1;
  25. export default {
  26. props: ['signinNum', 'totalCountNum'],
  27. watch: {
  28. totalCountNum(){
  29. this.getServerData()
  30. }
  31. },
  32. data() {
  33. return {
  34. cWidth3:'',//圆弧进度图
  35. cHeight3:'',//圆弧进度图
  36. arcbarWidth:'',//圆弧进度图,进度条宽度,此设置可使各端宽度一致
  37. pixelRatio:1,
  38. }
  39. },
  40. mounted() {
  41. _self = this;
  42. this.cWidth3=uni.upx2px(250);//这里要与样式的宽高对应
  43. this.cHeight3=uni.upx2px(250);//这里要与样式的宽高对应
  44. this.arcbarWidth=uni.upx2px(24);
  45. this.getServerData();
  46. },
  47. methods: {
  48. getServerData(){
  49. let percent = (parseInt(this.signinNum)/parseInt(this.totalCountNum)).toFixed(2);
  50. let Arcbar1={series:[{
  51. "name": "签到比例",
  52. "data": percent,
  53. "color": "#92bdfe"
  54. }]};
  55. _self.showArcbar("canvasArcbar1",Arcbar1);
  56. },
  57. showArcbar(canvasId,chartData){
  58. canvaArcbar1=new uCharts({
  59. $this:_self,
  60. canvasId: canvasId,
  61. type: 'arcbar',
  62. fontSize:11,
  63. legend:{show:false},
  64. background:'#FFFFFF',
  65. pixelRatio:_self.pixelRatio,
  66. series: chartData.series,
  67. animation: true,
  68. width: _self.cWidth3*_self.pixelRatio,
  69. height: _self.cHeight3*_self.pixelRatio,
  70. dataLabel: true,
  71. title: {
  72. name: Math.round(chartData.series[0].data*100)+'%',//这里我自动计算了,您可以直接给任意字符串
  73. color: chartData.series[0].color,
  74. fontSize: 25*_self.pixelRatio
  75. },
  76. subtitle: {
  77. name: chartData.series[0].name,//这里您可以直接给任意字符串
  78. color: '#666666',
  79. fontSize: 15*_self.pixelRatio
  80. },
  81. extra: {
  82. arcbar:{
  83. type:'circle',//整圆类型进度条图
  84. width: _self.arcbarWidth*_self.pixelRatio,//圆弧的宽度
  85. startAngle:0.5//整圆类型只需配置起始角度即可
  86. }
  87. }
  88. });
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. .top-font{
  95. font-size: 30rpx;
  96. text-indent: 1.5em;
  97. }
  98. .signbox{
  99. width: 100%;
  100. height: 85px;
  101. display: flex;
  102. }
  103. .sign-small-box{
  104. flex: 1;
  105. }
  106. .signNum{
  107. font-size: 76rpx;
  108. font-weight: 700;
  109. text-align: center;
  110. color: #e15632;
  111. }
  112. .nosignNum{
  113. font-size: 76rpx;
  114. font-weight: 700;
  115. text-align: center;
  116. color: #218d84;
  117. }
  118. .bottom-font{
  119. font-size: 30rpx;
  120. text-align: center;
  121. }
  122. .qiun-charts3 {
  123. height: 250upx;
  124. background-color: #FFFFFF;
  125. position: relative;
  126. display: flex;
  127. justify-content: space-around;
  128. }
  129. .charts3 {
  130. width: 250upx;
  131. height: 250upx;
  132. background-color: #FFFFFF;
  133. }
  134. </style>