2016-07-25 2 views
0

에 내가 plotband, 내가 PHP에서 x 축과 y 축 데이터에 액세스하고처럼, JQuery와 방법에 PHP와 액세스에서 보내는 plotedband JSON 싶어, 내가 동적으로 추가 할 highchart에 새로운 오전동적으로 추가 plotband highchart

**jQuery code** 

$(function() { 

    var plotband =''; 

     var options = { 
      chart: { 
       renderTo: 'containerline', 
       type: 'line', 
       plotShadow: false, 
       //marginRight: 130, 
       marginBottom: 55 
      }, 
      title: { 
       text: 'Portfolio UW vs Current CapEx', 
       x: -20 //center 
      }, 
      subtitle: { 
       text: '', 
       x: -20 
      }, 
      xAxis: { 
       categories: [], 
       plotBands: plotband, 
       labels: { 
        rotation: 270 

       }, 
       }, 
      yAxis: { 
       // title: { 
       //  text: 'Amount' 
       // }, 
       labels: { 
        format: '{value:,.0f}' 

       }, 
       plotLines: [{ 
        value: 0, 
        width: 1, 
        color: '#808080' 
       }] 
      }, 
      tooltip: { 
       formatter: function() { 
         return '<b>'+ this.series.name +'</b><br/>'+ 
         this.x +': '+ this.y; 
       } 
      }, 
      legend: { 
       layout: 'vertical', 
       align: 'right', 
       enabled: false, 
       verticalAlign: 'top', 
       x: -10, 
       y: 100, 
       borderWidth: 0 
      }, 
      lang: { 
       thousandsSep: ',' 
      }, 
      series: [], 
      exporting: { 
       enabled: false 
      }, 
      credits: { 
        enabled: false 
      }, 
     } 
     var hidden_portfolio_ids=$('#hidden_portfolio_id').val(); 
     $.getJSON('<?php echo base_url(); ?>controller/data_linechart/'+hidden_portfolio_ids+'', function(json) { 
      options.xAxis.categories = json[0]['data']; 
      options.series[0] = json[1]; 
      options.series[1] = json[2]; 
      options.plotband= json[3]; 
      chart = new Highcharts.Chart(options); 
     }); 
}); 

    **PHP Code** 



public function data_linechart($id) 
{ 

    $data = $this->model->get_linechart_data($id); 

    $category = array(); 
    $category['name'] = 'Category'; 

    $series1 = array(); 
    $series1['name'] = 'UW'; 

    $series2 = array(); 
    $series2['name'] = 'Proj'; 

    $series3 = array(); 
    $series3['name'] = 'Today'; 

    foreach ($data as $row) 
    { 
     $datepaid = new DateTime($row->pcs_linchartdrawdate); 
     $newdate= $datepaid->format('M-d'); 

     $category['data'][] = $newdate; 
     $series1['data'][] = $row->pcs_uw;  
     $series2['data'][] = $row->pcs_projected; 
     //$series3['data'][] = $row->pcs_today; 

    } 
    $plotband= "[{ 
     color: 'orange', 
     from:1, 
     to: 1.01 
    }]"; 

    $result = array(); 
    array_push($result,$category); 
    array_push($result,$series1); 
    array_push($result,$series2); 
    array_push($result,$plotband); 

    print json_encode($result, JSON_NUMERIC_CHECK); 
} 

내 데이터가 올 바르고 xAxis 및 yAxis가 올바르게 플롯되지만 플로팅 밴드를 PHP로 그리는 법

답변

1

$plodBand은 JSON 대신 문자열입니다.

$plotband = array[]; 

$plotband[0] = array(
     color => 'orange', 
     from => 1, 
     to= > 1.01 
); 

다음과 같이 차트 구성의 JSON에서 개체를 추출하십시오.