我正在开发一个在 CodeIgniter 框架中构建的 PHP 项目。此应用程序包含许多动态创建的图表。我在使用ronan-gloo highcharts library方面取得了巨大的成功。下面是生成我的图表的代码......
$this -> load -> library ( 'Highchart' );
$chart = new Highchart ( );
$chart -> chart -> renderTo = "divid";
$chart -> title -> text = "chart Title";
$chart -> xAxis -> categories = $xaxis;
$chart -> tooltip -> formatter = new HighchartJsExpr ( "function() {
var s;
if (this.point.name) { // the pie chart
s = ''+
this.point.name +': '+ this.y;
} else {
s = '<b>'+ this.series.name +'</b><br/><i>' + this.x +'</i>: <b>'+ this.y + '%</b>';
}
return s; }" );
$chart -> series [ ] = array (
'type' => "column" ,
'name' => "%age" ,
'data' => $yaxis ,
'color' => '#CC004B' ,
'showInLegend' => TRUE ,
'dataLabels' => array (
'enabled' => TRUE ,
'color' => '#CC004B' ,
'style' => array (
'fontSize' => '10px' ,
'verticalalign' => 'bottom'
)
)
);
foreach ( $chart->getScripts() as $script ) {
echo '<script type="text/javascript" src="' . $script . '"></script>';
}
echo "<script src='" . base_url ( ) . "assets/js/jquery.cookie.js'></script>";
echo "<script type='text/javascript' src='" . base_url ( ) . "assets/highcharts/js/exporting.js'></script>";
echo "<div id='divid'></div>";
echo "<script type='text/javascript'>" . $chart -> render ( "chart1" ) . "</script>";
这有助于我在更大范围内创建图表,但是,Highcharts 具有出色的向下钻取功能(High Charts Drilldown 演示),我希望在我的项目中实现它。
该演示建议创建保存向下钻取数据 ( JS Fiddle ) 的 javascript 对象,该对象被调用以创建图表。但是当javascript是动态编写的时,我怎么能在PHP Codeigniter中做到这一点......
请帮忙!