0

我有一个控制器,它输出一个用于绘制带有 highcharts 的图形的 json

1-首先我必须选择一个时间范围,将 timepicker 开始日期和结束日期变量传递给我的控制器,并根据这个时间获取数据并生成图表。

2-现在想要使用相同的 json 输出来绘制相同的数据,但以表格格式。

我可以使用 highchart 代码中使用的开始日期和结束日期来绘制带有数据表的表格吗?

我的 json 看起来像这样

{"name":"sensor_1","data":[["2012-12-01 15:00:00.070",45],["2012-12-01 15:00:00.281",95],["2012-12-01 15:00:00.883",104]]  ........]},"name":"sensor_2","data":[[]........]}

我用了这段代码

  $(document).ready(function(){ 

var startDateTextBox = $('#startDate');  ///  start date  passed to yii controller
var endDateTextBox = $('#endDate'); 

$("#btnSubmit").click(function() {
    if(startDateTextBox.val()!="" && endDateTextBox.val()!=""){
        $.ajax({
            type: "get",
            url: "<?php echo                  
                    CController::createUrl('ecg/GetSensorsData'); ?>",
            data: {"ecgId" : "<?php echo $modelsensors['node_id'] ;?>" , 
                  "sDate": $('#startDate').val() , "eDate": $('#endDate').val()},
            dataType:"json",
            success: function(response, status) {                   
                var chart;                      

                chart = new Highcharts.Chart({                   
                    chart: {                         
                        renderTo: 'container',
                         type: 'spline'                         
                    },  
                    },
                    xAxis: {
                        type: 'datetime',
                    },    
                    },
                    series: response
                });                     
            },
            error: function (response, status) {
                    alert("An error occured while loading 
                                          data!");
            }
        });
    }
    else
    {
        alert("Choose date range!")
           }   
});
startDateTextBox.datetimepicker({ 
    //showSecond: true,
    dateFormat : 'yy-mm-dd',
    timeFormat: 'HH:mm ',
    stepHour: 1,
    stepMinute: 1,
    //stepSecond: 0.5,

    onClose: function(dateText, inst) {
        if (endDateTextBox.val() != '') {
            var testStartDate = 
                  startDateTextBox.datetimepicker('getDate');
            var testEndDate = endDateTextBox.datetimepicker('getDate');
            if (testStartDate > testEndDate)
                endDateTextBox.datetimepicker('setDate', 
                                                       testStartDate);
        }
        else {
            endDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        endDateTextBox.datetimepicker('option', 'minDate',            
            startDateTextBox.datetimepicker('getDate') );
    }
});

endDateTextBox.datetimepicker({ 
    showSecond: true,
    dateFormat : 'yy-mm-dd',
    timeFormat: 'HH:mm:ss',
    stepHour: 1,
    stepMinute: 1,
    stepSecond: 0.5,
    onClose: function(dateText, inst) {
        if (startDateTextBox.val() != '') {
            var testStartDate = startDateTextBox.datetimepicker('getDate');
            var testEndDate = endDateTextBox.datetimepicker('getDate');
            if (testStartDate > testEndDate)
                startDateTextBox.datetimepicker('setDate', testEndDate);
        }
        else {
            startDateTextBox.val(dateText);
        }
    },
    onSelect: function (selectedDateTime){
        startDateTextBox.datetimepicker('option', 'maxDate', 
          endDateTextBox.datetimepicker('getDate') );
    }
});
      });
      </script>

在我看来,我获取所有数据,我想做与 highchart 相同的操作(过滤数据)

 <tbody>
 <?php  if(count($modelSensors)>=1) {
 foreach($modelSensors as $models) : ?>
 <tr>
 <td>  <?php echo $models['information_sensor_id'] ; ?> </td>
 <td> <?php echo $models['information_sensor_time'] ; ?> </td>
  <td> <?php echo $models['information_sensor_value'] ; ?> </td>    
  <td> <?php echo $models['sensor_id'] ; ?> </td>                                                 
  </tr>
  <?php endforeach; 
  }else {?>

   <tr>
   <td colspan='2' style="text-align:center;">Sorry no data found for this Node</td>
   </tr>
   <?php } ?>
  </tbody>

编辑:

    var_dump($modelSensors);
    array
    0 => 
    object(SensorInfo)[1384]
     private '_md' (CActiveRecord) => 
    object(CActiveRecordMetaData)[85]
        public 'tableSchema' => 
        object(CMysqlTableSchema)[98]
          ...
      public 'columns' => 
        array
          ...
      public 'relations' => 
        array
          ...
      public 'attributeDefaults' => 
        array
          ...
      private '_model' => 
        object(SensorInfo)[84]
          ...
      private '_new' (CActiveRecord) => boolean false
       private '_attributes' (CActiveRecord) => 
       array
      'information_sensor_id' => string '1' (length=1)
      'information_sensor_time' => string '2012-12-01 15:00:00' (length=19)
      'information_sensor_value' => string '95' (length=2)
      'sensor_id' => string 'sensor1' (length=7)
       ....................
4

0 回答 0