n-safety-monitoring-canva-4.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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="canvasPie" id="canvasPie" @touchstart="touchPie" style="width: 700upx; height:700upx;"></canvas>
  10. </view>
  11. </template>
  12. <script>
  13. import uCharts from '@/components/u-charts/u-charts.js';
  14. var _self;
  15. var canvaPie = 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(700);
  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 Pie = {
  38. series: [{
  39. name: '',
  40. data: 0
  41. }]
  42. }
  43. data.map(function(item, index) {
  44. //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
  45. var sevm = {};
  46. //给每一项中的参数初始化并赋值
  47. sevm['name'] = item.mine_name + " " + item.percent*100 + " %";
  48. sevm['data'] = item.count;
  49. //将项放进新的数组
  50. Pie.series[index] = sevm
  51. })
  52. // console.log(Pie)
  53. _self.showPie("canvasPie", Pie);
  54. })
  55. },
  56. showPie(canvasId, chartData) {
  57. canvaPie = new uCharts({
  58. $this: _self,
  59. canvasId: canvasId,
  60. type: 'pie',
  61. fontSize: 11,
  62. legend: {
  63. show: true,
  64. position: 'top',
  65. lineHeight: 20,
  66. },
  67. background: '#FFFFFF',
  68. pixelRatio: _self.pixelRatio,
  69. series: chartData.series,
  70. animation: true,
  71. width: _self.cWidth * _self.pixelRatio,
  72. height: _self.cHeight * _self.pixelRatio,
  73. dataLabel: false,
  74. extra: {
  75. pie: {
  76. lableWidth: 15
  77. }
  78. },
  79. });
  80. },
  81. touchPie(e) {
  82. canvaPie.showToolTip(e, {
  83. format: function(item) {
  84. return item.name + ' : ' + item.data
  85. }
  86. });
  87. },
  88. }
  89. }
  90. </script>
  91. <style lang="scss">
  92. .title {
  93. margin-bottom: 10rpx;
  94. display: flex;
  95. align-items: center;
  96. .icon {
  97. margin-right: 10rpx;
  98. image{
  99. width: 30rpx;
  100. height: 30rpx;
  101. }
  102. }
  103. .text {}
  104. }
  105. </style>