123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <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="canvasLineA" id="canvasLineA" @touchstart="touchLineA" style="width: 700rpx; height:500rpx;"></canvas>
- </view>
- </template>
- <script>
- import uCharts from '@/components/u-charts/u-charts.js';
- var _self;
- var canvaLineA = null;
- export default {
- data() {
- return {
- cWidth: '',
- cHeight: '',
- pixelRatio: 1,
- }
- },
- mounted() {
- _self = this;
- this.cWidth = uni.upx2px(700);
- this.cHeight = uni.upx2px(500);
- this.getServerData();
- },
- methods: {
- getServerData() {
- // let LineA = {
- // "categories": ['02-24', '02-25', '02-26', '02-27', '02-28', '03-01','03-02'],
- // "series": [{
- // name: '',
- // data: [0,0,0,0,0,7000,3027],
- // color: '#000000'
- // }]
- // };
-
- this.$api.jt_safety_alarm_total({
-
- }).then((res) => {
- // console.log(res.data.content)
-
- let LineA = {
- categories: [],
- data:[]
- }
-
- const categories = res.data.content.data
- categories.map(function(item,index){
- //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
- var sevm = {};
- //给每一项中的参数初始化并赋值
- sevm = item.every_date.slice(5);
- //将项放进新的数组
- LineA.categories[index] = sevm
- })
-
- const data = res.data.content.data
- data.map(function(item, index) {
- //新数组的项,用来盛放每一项中的各个参数,每次清空,这样避免改变sevm的值
- var sevm = {};
- //给每一项中的参数初始化并赋值
- sevm = item.every_count;
- //将项放进新的数组
- LineA.data[index] = sevm
- })
-
-
- // console.log(LineA)
-
- _self.showLineA("canvasLineA",LineA);
- })
- },
- showLineA(canvasId, chartData) {
- canvaLineA = new uCharts({
- $this: _self,
- canvasId: canvasId,
- type: 'line',
- fontSize: 11,
- legend: {
- show: false
- },
- dataLabel: false,
- dataPointShape: true,
- background: '#FFFFFF',
- pixelRatio: _self.pixelRatio,
- categories: chartData.categories,
- series: [{
- name: '',
- data: chartData.data,
- color: '#000000'
- }],
- animation: true,
- xAxis: {
- disableGrid: true,
- type: 'grid',
- gridColor: '#CCCCCC',
- gridType: 'dash',
- dashLength: 8
- },
- yAxis: {
- gridType: 'dash',
- gridColor: '#CCCCCC',
- dashLength: 8,
- splitNumber: 5,
- min: 10,
- max: 180,
- format: (val) => {
- return val.toFixed(0)
- }
- },
- width: _self.cWidth * _self.pixelRatio,
- height: _self.cHeight * _self.pixelRatio,
- extra: {
- line: {
- type: 'straight'
- }
- }
- });
- },
- touchLineA(e) {
- canvaLineA.showToolTip(e, {
- format: function(item, category) {
- return category + ' ' + item.name + ':' + item.data
- }
- });
- }
- }
- }
- </script>
- <style lang="scss">
- .title {
- margin-bottom: 60rpx;
-
- display: flex;
- align-items: center;
- .icon {
- margin-right: 10rpx;
- image{
- width: 30rpx;
- height: 30rpx;
- }
- }
- .text {}
- }
- </style>
|