我正在使用CodeIgniter PHP框架和HighCharts lib edited by Ronan Gloo,
目前我正在使用此代码呈现图表:
$arDATA = $this->m_charts->get_ar_data($this->m_charts->chart_test);
$this->highcharts->from_result($arDATA)
->set_type('bar')
->set_title('Title1', 'Subtitle1')
->add();
$data['charts'] = $this->highcharts->render();
var_dump($data['charts']);
//output :
<script type="text/javascript">
$(function(){
Highcharts.setOptions({"chart":{"backgroundColor":{"linearGradient":
[0,0,500,500],"stops":[[0,"rgb(255, 255, 255)"],
[1,"rgb(240, 240,255)"]]},"shadow":true},"plotOptions":{"series":
{"stacking":"normal"}}});
var chart_1 = new Highcharts.Chart({"series":[{"name":"n-2","data":
[200,150,350]}],"chart":{"renderTo":"hc_chart_1","type":"column"},"xAxis":
{"categories":["this","is a","graph"]},"title":{"text":"T1"},"subtitle":
{"text":"ST1_1"}});
});
为了将我的打印选项(下面的代码)包含在图表中,我尝试将其插入到$ data [&#39; charts&#39;]中,在系列之后使用以下内容展开字符串:(模式:&# 39;]}]&#39;标记系列的结尾)
$charts_arr = explode('*', str_replace(']}],', ']}],*', $data['charts']));
$charts_arr[2] = $charts_arr[1];
$charts_arr[1] = exportingOptions($uc, $dt, $ap);
public function exportingOptions($userConnected, $dateTime, $authorizationPrint) {
if ($authorizationPrint) {
$print = "exporting: {chartOptions: {chart: {events: "
. "{load: function () {"
. "this.renderer.text('-CONFIDENTIEL-', 75, 325).attr({rotation: -25}).add();"
. "this.renderer.text('$userConnected', 315, 290).attr({rotation: -25}).add();"
. "this.renderer.text('$dateTime', 190, 310).attr({rotation: -25}).add()}}}},"
. "buttons: {contextButton: {menuItems: [{text: 'Print Chart',onclick: function() {"
. "this.renderer.text('-CONFIDENTIEL-', 350, 350).attr({rotation: -25,id:'1'}).add();"
. "this.renderer.text('$userConnected', 600, 300).attr({rotation: -25,id:'2'}).add();"
. "this.renderer.text('$dateTime', 470, 330).attr({rotation: -25,id:'3'}).add();"
. "this.print(); $(\#1).remove(); $(\#2).remove(); $(\#3).remove();}}, {"
. "text: 'Download PNG image', onclick: function() {this.exportChart({type: 'image/png'});}},{"
. "text: 'Download JPEG image', onclick: function() {this.exportChart({type: 'image/jpeg'});}},{"
. "text: 'Download PDF document', onclick: function() {this.exportChart({type: 'application/pdf'});}},{"
. "text: 'Download SVG vector image', onclick: function() {this.exportChart({type: 'image/svg+xml'});},separator: false}]}}},";
} else {
$print = "exporting: {enabled: false},";
}
return $print;
}
但添加选项后图表不再显示。 如果需要,请不要犹豫,向我询问更多来源或解释。 欢迎提示:)
编辑:未捕获的SyntaxError:行中出现意外的标记ILLEGAL:
var chart_1 = new Highcharts.Chart({"series":[{"name":"n-2","data":[200,150,350]},{"name":"n-1","data":[225,175,375]},{"name":"n","data":[150,175,300]},{"name":"n+1","data":[300,200,400]},{"name":"n+2","data":[180,190,270]},{"name":"n+3","data":[230,140,250]}],exporting: {chartOptions: {chart: {events: {load: function () {this.renderer.text('-CONFIDENTIEL-', 75, 325).attr({rotation: -25}).css({color: '#FFE8E8',fontSize: '70px',}).add();this.renderer.text('NAME', 315, 290).attr({rotation: -25}).css({color: '#FFE8E8',fontSize: '30px',}).add();this.renderer.text('25-06-2014 13:20:41', 190, 310).attr({rotation: -25}).css({color: '#FFE8E8',fontSize: '30px',}).add()}}}},buttons: {contextButton: {menuItems: [{text: 'Print Chart',onclick: function() {this.renderer.text('-CONFIDENTIEL-', 350, 350).attr({rotation: -25,id:'1'}).css({color: '#FFE8E8',fontSize: '70px',}).add();this.renderer.text('NAME', 600, 300).attr({rotation: -25,id:'2'}).css({color: '#FFE8E8',fontSize: '30px',}).add();this.renderer.text('25-06-2014 13:20:41', 470, 330).attr({rotation: -25,id:'3'}).css({color: '#FFE8E8',fontSize: '30px'}).add();this.print(); $(\#1).remove(); $(\#2).remove(); $(\#3).remove();}}, {text: 'Download PNG image', onclick: function() {this.exportChart({type: 'image/png'});}},{text: 'Download JPEG image', onclick: function() {this.exportChart({type: 'image/jpeg'});}},{text: 'Download PDF document', onclick: function() {this.exportChart({type: 'application/pdf'});}},{text: 'Download SVG vector image', onclick: function() {this.exportChart({type: 'image/svg+xml'});},separator: false}]}}},"chart":{"renderTo":"hc_chart_1","type":"column"},"xAxis":{"categories":["this","is a","graph"]},"title":{"text":"T1"},"subtitle":{"text":"ST1_1"}});