我一直在使用jpgraph库来生成mdf中的图形。我面临的问题是我不想显示表值而只显示图表。因为在下面的例子中它显示了两者。 http://mpdf1.com/manual/index.php?tid=364 有没有办法做到这一点?请帮助。
谢谢!
<?php
include("../mpdf.php");
// This must be defined before including mpdf.php file
define("_JPGRAPH_PATH", '../../jpgraph_5/src/');
// Change these if necessary to the name of font files you can access from JPGraph
define("_TTF_FONT_NORMAL", 'arial.ttf');
define("_TTF_FONT_BOLD", 'arialbd.ttf');
$mpdf=new mPDF();
// This must be set to allow mPDF to parse table data
$mpdf->useGraphs = true;
$html = '
<table id="tbl_1"><tbody>
<tr><td></td><td><b>Female</b></td><td><b>Male</b></td></tr>
<tr><td>35 - 44</td><td><b>4</b></td><td><b>2</b></td></tr>
<tr><td>45 - 54</td><td><b>5</b></td><td><b>7</b></td></tr>
<tr><td>55 - 64</td><td><b>21</b></td><td><b>18</b></td></tr>
<tr><td>65 - 74</td><td><b>11</b></td><td><b>14</b></td></tr>
<tr><td>75 - 84</td><td><b>10</b></td><td><b>10</b></td></tr>
<tr><td>85 - 94</td><td><b>2</b></td><td><b>1</b></td></tr>
<tr><td>95 - 104</td><td><b>1</b></td><td><b></b></td></tr>
<tr><td>TOTAL</td><td>54</td><td>52</td></tr>
</tbody></table>
<jpgraph table="tbl_1" type="bar" title="New subscriptions" label-y="% patients" label-x="Age group" series="cols" data-row-end="-1" show-values="1" width="600" legend-overlap="1" hide-grid="1" hide-y-axis="1" />
';
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>
答案 0 :(得分:0)
像这样更改你的表:
<table id="tbl_1" style="display:none">
答案 1 :(得分:0)
尝试为要隐藏的元素提供类,并在单独的样式表中控制它们,仅用于PDF。
$html = "<body><div class='hide-this'></div></body>";
使用media="print"
声明样式表:
<link rel="stylesheet" type="text/css" href="pdf.css" media="print">
在样式表中:
.hide-this{
display: none;
}
请注意,display
仅适用于mPDF中的块级元素。
答案 2 :(得分:0)
使用以下代码
include("../mpdf.php");
$mpdf=new mPDF();
$graphLink = 'graphPage.php?id=1'; // create a new file, you can pass parameter to it also.
$html .= '<div><img src="'.$graphLink.'" ></div>';
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
“graphPage.php”的代码
// graphPage.php
include_once("../PATH_TO_JPGRAPH/src/jpgraph.php");
require_once ('../PATH_TO_JPGRAPH/src/jpgraph_bar.php');
$id = (int)$_GET['id'];
$data1y=array(47,80,40,116);
$data2y=array(61,30,82,105);
$data3y=array(115,50,70,93);
// Create the graph. These two calls are always required
$graph = new Graph(350,200,'auto');
$graph->SetScale("textlin");
$graph->yaxis->SetTickPositions(array(0,30,60,90,120,150), array(15,45,75,105,135));
$graph->SetBox(false);
$graph->SetFrame(false);
$graph->SetFrameBevel(1,false,'#ffffff','#ffffff','#ffffff');
$graph->ygrid->SetFill(false);
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b2plot = new BarPlot($data2y);
$b3plot = new BarPlot($data3y);
// Create the grouped bar plot
$gbplot = new GroupBarPlot(array($b1plot,$b2plot,$b3plot));
// ...and add it to the graPH
$graph->Add($gbplot);
$b1plot->SetColor("white");
$b1plot->SetFillColor("#95c11f");
$b2plot->SetColor("white");
$b2plot->SetFillColor("#11cccc");
$b3plot->SetColor("white");
$b3plot->SetFillColor("#1111cc");
$graph->title->Set("My Bar Graph");
// Display the graph
$graph->Stroke();