historyAlarmChart_frm.html 10.8 KB
<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
      <title>报警信息历史报表_frm</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/statistic/statistic.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
      <link rel="stylesheet" type="text/css" href="../../css/history/history.css"/>
      <style>
          html,
          body{
            background-color: #F4F6F9;
          }
      </style>
  </head>
  <body>
    <div style="background-color:#FFFFFF;">
      <div class="measure-title">
        <div style="margin-left:15px;margin-right:15.5px;">
          <div class="aui-row aui-row-flex top-14">
            <div class="aui-col aui-col-span-1" style="margin-top: 1rem;">
              <div class="title-sign"></div>
            </div>
            <div class="aui-col aui-col-span-23">
              <span class="device-name" id="device_imei">设备编号:</span>
            </div>
          </div>
          <div style="margin-top:17.5px;margin-bottom:12px;height:1px;background:#F0F5FF;"></div>
        </div>
      </div>
      <div class="search-view-inline">
          <div class="select-list aui-ellipsis-1" style="width:50%;" tapmode id="select-date" onclick="selectDay();">
              <span class="choose-device-title" id="choose_history_day">按日</span>
              <i></i>
          </div>
          <label style="background-color:rgba(240,245,255,1);"></label>
          <div class="select-list aui-ellipsis-1" style="width:50%;" tapmode id="select-time" onclick="selectTime();">
              <span class="choose-device-title" id="choose_history_time">选择开始日期</span>
              <i></i>
          </div>
      </div>
    </div>
    <div class="history-alarm-title">
      <div class="aui-row aui-row-flex top-14">
        <div class="aui-col aui-col-span-12 aui-row-flex-start alarm-title">
          当日报警历史数据分析
        </div>
        <div class="aui-col aui-col-span-12 aui-row-flex-end alarm-tip">
          数据来自实时采集
        </div>
      </div>
    </div>
    <div class="echart-area">
      <div class="inside-echart-area" id="echart_area">
      </div>
      <div style="margin-top:20px;height:10px;"></div>
    </div>
  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
  <script type="text/javascript" src="../../script/common.js"></script>
  <script type="text/javascript" src="../../script/echarts.min.js"></script>
  <script type="text/javascript">
    var defaultImei;
    var token;
    var userId;
    var select_day = 1;  //1.按日2.按月3.按年
    var select_time = '';
      apiready = function(){
        api.parseTapmode();
        defaultImei = $api.getStorage('defaultDevice');
        token = $api.getStorage('userToken');
        userId = $api.getStorage('userID');
        $api.html($api.byId("device_imei"), '设备编号:'+ defaultImei);
        select_time = parseTime(new Date(),'{y}-{m}-{d}');
        $api.html($api.byId("choose_history_time"), select_time);
        api.addEventListener({
            name: 'changeHistoryChartType'
        }, function(ret, err){
            if( ret ){
              switch (ret.value.curSelect) {
                case 1:
                  $api.html($api.byId("choose_history_day"), '按日');
                  select_day = 1;
                  break;
                case 2:
                  $api.html($api.byId("choose_history_day"), '按月');
                  select_day = 2;
                  break;
                case 3:
                  $api.html($api.byId("choose_history_day"), '按年');
                  select_day = 3;
                  break;
                default:
                $api.html($api.byId("choose_history_day"), '按日');
                  select_day = 3;
              }
              loadChartInfo();
            }
        });

        loadChartInfo();
      };



    function selectDay() {
      api.openFrame({
          name: 'historyDaliySelecter',
          url: './historyChartDaliySelecter.html',
          rect: {
              x: 0,
              y: api.pageParam.h,
              w: api.frameWidth,
              h: api.winHeight-api.pageParam.h-api.pageParam.f
          },
          pageParam: {
              selected: select_day,
          },
          bounces: false,
          animation: {
              type:"fade",                //动画类型(详见动画类型常量)
              subType:"from_bottom",       //动画子类型(详见动画子类型常量)
              duration:300                //动画过渡时间,默认300毫秒
          }
      });
    }

    function selectTime() {
      api.openPicker({
          type: 'date',
          date: 'yyyy',
          title: '选择日期',
      }, function(ret, err) {
        if (ret) {
          var select_time_ = parseTime(new Date(timeFormater(ret.year,ret.month,ret.day)),'{y}-{m}-{d}');
          select_time = select_time_;
          if (select_day == 1) {
            $api.html($api.byId("choose_history_time"), select_time_.slice(0,11));
          }else if (select_day == 2) {
            $api.html($api.byId("choose_history_time"), select_time_.slice(0,7));
          }else if (select_day == 3) {
            $api.html($api.byId("choose_history_time"), select_time_.slice(0,4));
          }
          loadChartInfo();
        }
      });
    }

    function loadChartInfo() {
      if (select_day == 1) {
        select_time = select_time.slice(0,11);
      }else if (select_day == 2) {
        select_time = select_time.slice(0,7);
      }else if (select_day == 3) {
        select_time = select_time.slice(0,4);
      }
      $api.html($api.byId("choose_history_time"), select_time);
      console.log(HOST + '/iot_api/v1/app/chart_report?time=' + select_time + '&type=' + select_day + '&imei=' + defaultImei);
      api.ajax({
        url:HOST + '/iot_api/v1/app/chart_report?time=' + select_time + '&type=' + select_day + '&imei=' + defaultImei,
        method: 'GET',
        headers: {
          'Content-Type': 'application/json;charset=utf-8',
          'token': token
        },
      }, function(ret, err) {
        if (ret.code == 0) {
          //柱状图
          var dom1 = $api.byId("echart_area");
          var myChart = echarts.init(dom1);
          console.log(JSON.stringify(ret));
          var dom1DataX = ret.data.xdata;
          var dom1DataY = ret.data.y_warning_data;


          option = {
              title: {
                  left: 'center',
                  text: '历史报警统计',
              },
              color: ['#5B7FF8'],
              tooltip : {
                  trigger: 'axis',
                  axisPointer : {            // 坐标轴指示器,坐标轴触发有效
                      type : 'shadow'        // 默认为直线,可选为:'line' | 'shadow'
                  }
              },
              grid: {
                  left: '0%',
                  right: '4%',
                  bottom: '20%',
                  containLabel: true
              },
              xAxis : [
                  {
                      type : 'category',
                      data : dom1DataX,
                      axisTick: {
                          alignWithLabel: true
                      },
                      axisLine: {
                          lineStyle: {
                              color: '#818295'
                          }
                      },
                      axisLabel: {
                        textStyle: {
                          color: function (value, index) {
                              return '#818295';
                          },
                          fontSize: 8,
                        },
                        rotate:330
                      }
                  }
              ],
              yAxis : [
                  {
                      type : 'value',
                      axisLine: {
                         lineStyle: {
                             color: '#fff'
                         }
                      },
                      axisLabel: {
                          textStyle: {
                            color: function (value, index) {
                                return value >= 10 ? 'red' : '#818295';
                            }
                          }
                      },
                      splitLine:{
                        show:true  ,
                        lineStyle:{
                          color:'#F0F5FF',
                          width: 1
                        }
                      }
                  }
              ],
              series : [
                  {
                      name:'报警总数',
                      type:'bar',
                      barWidth: '60%',
                      data:dom1DataY,
                      // 折线颜色
                      itemStyle: {
                       normal: {
                           color: '#5B7FF8',
                           lineStyle: {
                               color: '#5B7FF8'
                           }
                       }
                      },
                  },
              ],
              dataZoom: [
                {
                  type: 'slider',
                  fillerColor: '#B0C8FF',
                  backgroundColor: '#F0F5FF',
                  start: 0,
                  end: 100,
                  handleIcon: "M0,0 v9.7h5 v-9.7h-5 Z",
                  // handleSize: '60%',
                  handleStyle: {
                      color: '#5B7FF8',
                      // shadowBlur: 1,
                      // shadowColor: 'rgba(0, 0, 0, 0.6)',
                      // shadowOffsetX: 2,
                      // shadowOffsetY: 2
                  },

                  dataBackground:{
                      lineStyle:{
                          color:'#F0F5FF'
                      },
                      areaStyle:{
                          color:'#F0F5FF',
                          opacity:1,
                      }
                  },
                  bottom:'0%'
                },{
                    type: 'inside',//这个 dataZoom 组件是 inside 型 dataZoom 组件(能在坐标系内进行拖动,以及用滚轮(或移动触屏上的两指滑动)进行缩放)
                    xAxisIndex: 0,//控制x轴
                }
              ],
          };

          if (option && typeof option === "object") {
              myChart.setOption(option, true);
          }
        }
      });
    }
  </script>
  </html>