我想生成一个包含一些信息的 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 不是强制性的。我看到谷歌图表看起来非常完美,而且看起来很容易使用。我可以使用这个:
<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 标签……那么我能做什么呢?请帮忙。谢谢