首先,我使用PhantomJS Webserver,HighCharts 3运行良好,它可以非常快速地生成图表。
在下面的代码中,您会注意到我正在尝试在$ legend值中添加“this.name”。
无论出于什么原因,一切都很有效,直到我尝试连接动态HighCharts this.name。
静态地,代码效果很好,如果我注释掉$ legend,那么图表看起来很棒。
在下面的$ legend值示例中,您将看到我试图逃避双引号的位置。
感谢任何帮助...
<?PHP
$renderTo = "chart: { renderTo: 'container_chartFreqAtaTailNum', type: 'bar' }";
$title = "title: { text: 'Frequency by Tail Number' }";
$subtitle = "subtitle: { text: 'Fact ATA (20)' }";
$xAxis = "xAxis: { categories: ['213','442','792'], title: { text: 'Tail Number' }, labels: { style: { width: '12000px' } } }";
$yAxis = "yAxis: { min: 0, title: { text: 'Count', align: 'high' }, labels: { overflow: 'justify' } }";
$tooltip = "tooltip: { formatter: function() { return ''+ this.series.name +': '+ this.y +' Count'; } }";
$plotOptions = "plotOptions: { bar: { dataLabels: { enabled: true } }, series: { pointWidth:10, groupPadding: .05, shadow: true } }";
$legend = "legend: { layout: 'horizontal', align: 'center', verticalAlign: 'bottom', floating: false, borderWidth: 1, backgroundColor: '#FFFFFF', shadow: true, labelFormatter: function() { return '<div class=\"' + this.name + '-arrow\"></div><span style=\"font-family: 'Advent Pro', sans-serif; font-size:12px\">' + this.name +'</span><br/><span style=\"font-size:10px; color:#ababaa\"> Total: ' + this.options.total + '</span>'; } }";
$credits = "credits: { enabled: false }";
$exporting = "exporting: { enabled: true }";
$series = "series: [{ name: 'Heavy', total: '2', data: [null,null,2] },{ name: 'Intermediate', total: '5', data: [null,2,3] },{ name: 'Line', total: '0', data: [null,null,null] },{ name: 'Lite', total: '6', data: [2,2,2] }]";
$json = '{"infile":"{'.$renderTo.','.$title.','.$subtitle.','.$xAxis.','.$yAxis.','.$tooltip.','.$plotOptions.','.$legend.','.$credits.','.$exporting.','.$series.'};","constr":"Chart","outfile":"/var/www/node/image/chart.png"}';
$ch = curl_init("http://127.0.0.1:3003");
# Setup request to send json via POST.
curl_setopt( $ch, CURLOPT_POSTFIELDS, $json );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
// header('Content-Type: image/png');
// echo base64_decode($result);
$fp = fopen('files/chart.png', 'w');
fwrite($fp, base64_decode($result));
fclose($fp);
?>
<img src="files/chart.png">
答案 0 :(得分:1)
我想我已经找到了你的问题。您需要为“Advent Pro&#39;”提供一套单引号。
试试这个:
$legend = "legend: { layout: 'horizontal', align: 'center', verticalAlign: 'bottom', floating: false, borderWidth: 1, backgroundColor: '#FFFFFF', shadow: true, labelFormatter: function() { return '<div class=\"' + this.name + '-arrow\"></div><span style=\"font-family: \'Advent Pro\', sans-serif; font-size:12px\">' + this.name +'</span><br/><span style=\"font-size:10px; color:#ababaa\"> Total: ' + this.options.total + '</span>'; } }";
答案 1 :(得分:0)
通过将此行更新为:
来修复上述代码$ legend ='legend:{layout:\'horizontal \',align:\'center \',verticalAlign:\'bottom \',floating:false,borderWidth:1,backgroundColor:\'#FFFFFF \' ,shadow:true,labelFormatter:function(){return \'\'+ this.name + \'\'; }}';