0
我是新的highchart,我想動態添加plotband,我想從PHP和訪問jQuery的方法來發送plotedband JSON,像我從PHP訪問X軸和Y軸的數據動態添加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);
}
我所有的數據來正確的X軸和Y軸和正確繪製,但如何用PHP繪製plotband,