0

まず、HighCharts 3 を搭載した PhantomJS Webserver を使用して、非常に高速にグラフを作成します。

次のコードでは、$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">
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\', shadow: true, labelFormatter: function() { return \'\'+ this.name +\'\'; } }';

于 2013-09-12T19:29:09.893 に答える