0

First I have PhantomJS Webserver with HighCharts 3 running great, it produces charts extremely fast.

In the following code you'll notice I'm trying to add "this.name" in the $legend value.

For whatever reason everything works great until I try to concatenate dynamic HighCharts this.name.

Statically the code works great and if I comment out $legend the chart looks great.

In the $legend value example below you'll see where I'm trying to escape the double quotes.

Any help is appreciated thanks...

<?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">
4

2 回答 2

1

我想我找到了你的问题。对于“Advent Pro”,您需要转义一组单引号。

尝试这个:

$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>'; } }";
于 2013-09-12T17:55:45.623 回答
0

通过将此行更新为:

$legend = 'legend: { layout: \'horizo​​ntal\', align: \'center\', verticalAlign: \'bottom\', floating: false, borderWidth: 1, backgroundColor: \'#FFFFFF\', 阴影: true, labelFormatter: function() { return \'\'+ this.name +\'\'; } ';

于 2013-09-12T19:29:09.893 回答