n-safety-monitoring-canva-1.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view>
  3. <view class="title">
  4. <view class="icon">
  5. <image src="./icon/icon_o.png" mode=""></image>
  6. </view>
  7. <view class="text">当日总报警</view>
  8. </view>
  9. <canvas canvas-id="canvasRing" id="canvasRing" @touchstart="touchRing" style="width: 700rpx; height:1100rpx;"></canvas>
  10. </view>
  11. </template>
  12. <script>
  13. import uCharts from '@/components/u-charts/u-charts.js';
  14. var _self;
  15. var canvaRing = null;
  16. export default {
  17. data() {
  18. return {
  19. cWidth: '',
  20. cHeight: '',
  21. pixelRatio: 1,
  22. serverData: '',
  23. }
  24. },
  25. mounted() {
  26. _self = this;
  27. this.cWidth = uni.upx2px(700);
  28. this.cHeight = uni.upx2px(1100);
  29. this.getServerData();
  30. },
  31. methods: {
  32. getServerData() {
  33. this.$api.jt_safety_alarm_count({
  34. }).then((res) => {
  35. // console.log(res.data.content)
  36. let data = res.data.content.data
  37. let Ring = {
  38. series: [{
  39. name: '',
  40. data: 0
  41. }],
  42. total: 0
  43. }
  44. data.map(function(item, index) {
  45. //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
  46. var sevm = {};
  47. //给每一项中的参数初始化并赋值
  48. sevm['name'] = item.mine_name + " " + item.count + " 个";
  49. sevm['data'] = item.count;
  50. //将项放进新的数组
  51. Ring.series[index] = sevm
  52. })
  53. Ring.total = res.data.content.total
  54. // console.log(Ring)
  55. _self.showRing("canvasRing", Ring);
  56. })
  57. },
  58. showRing(canvasId, chartData) {
  59. canvaRing = new uCharts({
  60. $this: _self,
  61. canvasId: canvasId,
  62. type: 'ring',
  63. fontSize: 12,
  64. legend: {
  65. show: true,
  66. position: 'bottom',
  67. lineHeight: 30,
  68. },
  69. title: {
  70. name: chartData.total + "个",
  71. color: '#000000',
  72. fontSize: 28 * _self.pixelRatio,
  73. offsetY: 30 * _self.pixelRatio,
  74. },
  75. subtitle: {
  76. name: '总报警量',
  77. color: '#666666',
  78. fontSize: 18 * _self.pixelRatio,
  79. offsetY: -30 * _self.pixelRatio,
  80. },
  81. extra: {
  82. pie: {
  83. offsetAngle: -90,
  84. ringWidth: 40 * _self.pixelRatio,
  85. labelWidth: 20
  86. }
  87. },
  88. background: '#FFFFFF',
  89. pixelRatio: _self.pixelRatio,
  90. series: chartData.series,
  91. animation: true,
  92. width: _self.cWidth * _self.pixelRatio,
  93. height: _self.cHeight * _self.pixelRatio,
  94. disablePieStroke: true,
  95. dataLabel: false,
  96. });
  97. },
  98. touchRing(e) {
  99. canvaRing.showToolTip(e, {
  100. format: function(item) {
  101. // return item.name + ' : ' + item.data + ' 个'
  102. return item.name
  103. }
  104. });
  105. },
  106. }
  107. }
  108. </script>
  109. <style lang="scss">
  110. .title {
  111. display: flex;
  112. align-items: center;
  113. .icon {
  114. margin-right: 10rpx;
  115. image{
  116. width: 30rpx;
  117. height: 30rpx;
  118. }
  119. }
  120. .text {}
  121. }
  122. </style>