php - Dynamically add plotband in highchart -
i new in highchart, want add dynamically plotband , want send plotedband json php , access in jquery method, accessing xaxis , yaxis data php
**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 $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); }
all data coming correct , xaxis , yaxis plotting correctly how draw plotband php,
your $plodband
string instead of json. use like:
$plotband = array[]; $plotband[0] = array( color => 'orange', => 1, to= > 1.01 );
and extract object json in chart configuration.
Comments
Post a Comment