いくつかの情報を含む PDF ファイルを生成し、それをいくつかの電子メール アドレスに送信したいと考えています。PDF 内の情報には、jpgraph を使用して生成した PIE が含まれます。もちろん、グラフは動的であるため、静的な PIE を生成して静的な画像として使用することはできません。生成する PDF ごとに、パイは異なります。しかし、それを行う方法(tcpdfに含める方法)についてはわかりません。これは私のチャートです:
<?php // content="text/plain; charset=utf-8"
require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_pie.php');
$sta = $_REQUEST['start'];
$sto = $_REQUEST['end'];
// Some data
$data = array($sta,$sto);
$color = array('#2ecc71','#e74c3c');
// A new pie graph
$graph = new PieGraph(400,400,'auto');
// Don't display the border
$graph->SetFrame(false);
// Uncomment this line to add a drop shadow to the border
// $graph->SetShadow();
// Setup title
$graph->title->Set("Procentaj realizat");
$graph->title->SetFont(FF_FONT1,FS_BOLD,18);
$graph->title->SetMargin(8); // Add a little bit more margin from the top
// Create the pie plot
$p1 = new PiePlotC($data);
// Set size of pie
$p1->SetSize(0.35);
// Label font and color setup
$p1->value->SetFont(FF_FONT1,FS_BOLD,12);
$p1->value->SetColor('white');
$p1->value->Show();
// Setup the title on the center circle
$p1->midtitle->Set("Procent\nraspunsuri corecte\n83%");
$p1->midtitle->SetFont(FF_FONT1,FS_NORMAL,14);
// Set color for mid circle
$p1->SetMidColor('white');
// Use percentage values in the legends values (This is also the default)
$p1->SetLabelType(PIE_VALUE_PER);
$p1->SetSliceColors($color);
// The label array values may have printf() formatting in them. The argument to the
// form,at string will be the value of the slice (either the percetage or absolute
// depending on what was specified in the SetLabelType() above.
$lbl = array("corecte\n%.1f%%","gresite\n%.1f%%");
$p1->SetLabels($lbl);
// Uncomment this line to remove the borders around the slices
// $p1->ShowBorder(false);
// Add drop shadow to slices
$p1->SetShadow();
// Explode all slices 15 pixels
$p1->ExplodeAll(15);
// Add plot to pie graph
$graph->Add($p1);
// .. and send the image on it's marry way to the browser
$graph->Stroke();
?>
したがって、上記のコードは mychart.php というファイルにあります。この結果を tcpdf ファイルに含めたいと思います。これどうやってするの?
jpgraph の使用は必須ではありません。Google チャートは非常に完璧に見え、使いやすいように見えます。私はこれを使うことができます:
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Corecte', 83]
]);
var options = {
width: 400, height: 250,
redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id='chart_div'></div>
</body>
</html>
ただし、tcpdf に含める場合は、まだ問題があります...つまり、tcpdf の HTML 内にスクリプトを追加する必要があります。問題は、tcpdf が body タグしか取得しないように見えることです...それで、なにかお手伝いできますか?助けてください。ありがとう