<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="utf-8"%>
<%@include file="/WEB-INF/ehr/commons/jsp/commonInclude.jsp" %>

<script src="${contextRoot}/develop/lib/jquery/jquery-1.9.1.js"></script>
<script src="${contextRoot}/develop/lib/plugin/switchery/switchery.js"></script>
<script src="${staticRoot}/echarts/echarts.js"></script>
<script>
//  function getTistoryGrid(selTask){
//    if(selTask!=""){
////由于文档div还没生成，延迟加载表格
//      setTimeout(function(){
//        taskHistoryGrid = $("#div_task_history_grid").ligerGrid($.LigerGridEx.config({
//          url: contextRoot+'/task/historyTasks',
//          method:'GET',
//          newPage:1,
//          parms: {
//            jobType:selTask,
//          },
//          columns: [
//            { display: '任务开始时间', name: 'beginDate', width: '20%' },
//            { display: '任务结束时间', name: 'endDate', width: '20%' },
//            { display: '执行总数', name: 'totalNum', width: '15%' },
//            { display: '采集成功数', name: 'succNum', width: '15%' },
//            { display: '上传成功数', name: 'uploadNum', width: '15%' },
//            { display: '注册成功数', name: 'registerNum', width: '15%' }
//          ],
//          inWindow: false,
//          enabledEdit: true,
//          validate : true,
//          unSetValidateAttr:false
//        }));
//        if(taskHistoryGrid!=null){
//          taskHistoryGrid.adjustToWidth();
//        }
//      }, 0);
//
//    }
//  }

  //获取某次采集情况数据
  $.ajax({
    type: "GET",
    url : "${contextRoot}/serverEnv/usage",
    dataType : "json",
    data:{type:"cpu",beginTime:"2015-10-22 00:00:00",endTime:"2016-10-31 00:00:00"},
    cache:false,
    success :function(re){
      if(re.successFlg) {
        var data = re.data;
        if(data!=null && data.length>0)
        {
          var count = 0
          var success =0;
          var x = [];
          var y1=[];
          var y2=[];
          for(var i=0;i<data.length;i++)
          {
            count += data[i].data.totalPerc;
            success += data[i].data.userPerc;
            x.push(data[i].create_date);
            y1.push(data[i].data.totalPerc);
            y2.push(data[i].data.userPerc);
          }
          // 基于准备好的dom，初始化echarts实例
          var myChart = echarts.init(document.getElementById('main'));

          // 指定图表的配置项和数据
          var option = {
            title: {
              text: 'CPU 指标测试',
              left: 'center'
            },
            tooltip: {
              trigger: 'item',
              formatter: '{b} <br/>{a} : {c}'
            },
            legend: {
              left: 'left',
              data: ['2的指数', '3的指数']
            },
            xAxis: {
              type: 'category',
              name: 'x',
              splitLine: {show: false},
              data: x
            },
            grid: {
              left: '3%',
              right: '4%',
              bottom: '3%',
              containLabel: true
            },
            yAxis: {
              type: 'log',
              name: 'y'
            },
            series: [
              {
                name: '使用率',
                type: 'line',
                data: y1
              }
            ]
          };
          myChart.setOption(option);
        }
        else{
          me.clearTop();
        }
      }
      else{
        $.ligerDialog.error(re.message);
      }
    },
    error :function(data){
      $.ligerDialog.error("Status:"+data.status +"(" +data.statusText+")");
    }
  });

</script>
