2014-02-06 3 views
1

codeigniter를 사용하고 있으며 PHP에서 다차원 배열로 그래프를 채울 필요가 있습니다.PHP에서 다차원 배열로 morris.js 차트 채우기

두 가지 기능을 사용하여 데이터를 가져옵니다. 사람들은 "get_num_instalaciones_mes"와 "get_num_bajas는"(INT)

function ajax_instalaciones_3meses() { 
    $fecha['mes'] = date('m'); 
    $fecha['anio'] = date('Y'); 
    $output['num_instalaciones_actual'] = get_num_instalaciones_mes($fecha['mes'], $fecha['anio']); 
    $fecha = $this->v3_operaciones_model->mes_anterior($mes, $anio); 
    $output['num_instalaciones_1menos'] = get_num_instalaciones_mes($fecha['mes'], $fecha['anio']); 
    $fecha = $this->v3_operaciones_model->mes_anterior($mes, $anio); 
    $output['num_instalaciones_2menos'] = get_num_instalaciones_mes($fecha['mes'], $fecha['anio']); 
    echo json_encode($output); 
} 

function ajax_bajas_3meses() { 
    $fecha['mes'] = date('m'); 
    $fecha['anio'] = date('Y'); 
    $output['num_bajas_actual'] = get_num_bajas_mes($fecha['mes'], $fecha['anio']); 
    $fecha = $this->v3_operaciones_model->mes_anterior($mes, $anio); 
    $output['num_bajas_1menos'] = get_num_bajas_mes($fecha['mes'], $fecha['anio']); 
    $fecha = $this->v3_operaciones_model->mes_anterior($mes, $anio); 
    $output['num_bajas_2menos'] = get_num_bajas_mes($fecha['mes'], $fecha['anio']); 
    echo json_encode($output); 
} 

숫자를 반환 배열을 반환하는 기능이며,이 '데이터'가있는보기에서 차트를 채우는 코드 (: INSTALACIONES, Z : bajas Y) I는 (다른 페이지) PHP 출력 데이터를 얻는 후 JSON 객체 모리스의 데이터를 채워 JSON을 사용

new Morris.Bar({ 
     element: 'graf_instalaciones_bajas', 
     data: [ 
      {x: 'AGO-2013', y: 20, z: 5}, 
      {x: 'SEP-2013', y: 40, z: 5}, 
      {x: 'OCT-2013', y: 33, z: 10}, 
      {x: 'NOV-2013', y: 24, z: 1}, 
      {x: 'DIC-2013', y: 44, z: 10}, 
      {x: 'ENE-2014', y: 31, z: 5} 
     ], 
     barColors: ['#00FF00', '#FF0000'], 
     xkey: 'x', 
     ykeys: ['y', 'z'], 
     labels: ['Instalaciones', 'Bajas'] 
    }).on('click', function(i, row){ 
    console.log(i, row); 
    }); 

답변

2

어레이 I는 모두 기능 채울 필요 .

거친 예 :이 도움이

var array = []; 

function myData() { 
    $.getJSON('data_source_link', function(data) { 
     array = data; 
     console.log(JSON.stringify(array)); // to ensure the data is actually captured 
    } 
    return array; 
} 

var myChart = Morris.Line({ 
    element: 'graph', 
    xkey: 'your_x_key', 
    ykeys: 'your_y_keys', 
    labels: ['Your Labels'], 
    ... 
}); 

setInterval(function() { 
    myChart.setData(myData()); 
}, 1000); 

희망. :)

관련 문제