123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <template>
- <view>
- <view class="title">
- <view class="icon">
- <image src="./icon/icon_o.png" mode=""></image>
- </view>
- <view class="text">当日报警分布</view>
- </view>
- <canvas canvas-id="canvasPie" id="canvasPie" @touchstart="touchPie" style="width: 700upx; height:700upx;"></canvas>
- </view>
- </template>
- <script>
- import uCharts from '@/components/u-charts/u-charts.js';
- var _self;
- var canvaPie = null;
- export default {
- data() {
- return {
- cWidth: '',
- cHeight: '',
- pixelRatio: 1,
- serverData: '',
- }
- },
- mounted() {
- _self = this;
- this.cWidth = uni.upx2px(700);
- this.cHeight = uni.upx2px(700);
- this.getServerData();
- },
- methods: {
- getServerData() {
-
- this.$api.jt_safety_alarm_count({
-
- }).then((res) => {
- // console.log(res.data.content)
-
- let data = res.data.content.data
-
- let Pie = {
- series: [{
- name: '',
- data: 0
- }]
- }
-
- data.map(function(item, index) {
- //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
- var sevm = {};
- //给每一项中的参数初始化并赋值
- sevm['name'] = item.mine_name + " " + item.percent*100 + " %";
- sevm['data'] = item.count;
- //将项放进新的数组
- Pie.series[index] = sevm
- })
-
-
- // console.log(Pie)
-
- _self.showPie("canvasPie", Pie);
-
- })
- },
- showPie(canvasId, chartData) {
- canvaPie = new uCharts({
- $this: _self,
- canvasId: canvasId,
- type: 'pie',
- fontSize: 11,
- legend: {
- show: true,
- position: 'top',
- lineHeight: 20,
- },
- background: '#FFFFFF',
- pixelRatio: _self.pixelRatio,
- series: chartData.series,
- animation: true,
- width: _self.cWidth * _self.pixelRatio,
- height: _self.cHeight * _self.pixelRatio,
- dataLabel: false,
- extra: {
- pie: {
- lableWidth: 15
- }
- },
- });
- },
- touchPie(e) {
- canvaPie.showToolTip(e, {
- format: function(item) {
- return item.name + ' : ' + item.data
- }
- });
- },
- }
- }
- </script>
- <style lang="scss">
- .title {
- margin-bottom: 10rpx;
- display: flex;
- align-items: center;
- .icon {
- margin-right: 10rpx;
- image{
- width: 30rpx;
- height: 30rpx;
- }
- }
- .text {}
- }
- </style>
|