【问题标题】:How to show graphs only in mPDF but not the tables?如何仅在 mPDF 中显示图形而不在表格中显示?
【发布时间】:2015-07-14 06:31:26
【问题描述】:

我一直在使用 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;

?>

【问题讨论】:

    标签: php mpdf jpgraph


    【解决方案1】:

    像这样改变你的表:

    <table id="tbl_1" style="display:none">
    

    【讨论】:

    • 我试过这个没有成功。我还尝试了其他解决方法,如下所示:
    • 你有任何带有任何表格显示选项和 !important 的 css 文件吗?这将覆盖本地定义。
    【解决方案2】:

    尝试为要隐藏的元素提供类,并在单独的样式表中控制它们,仅用于 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 中的块级元素。

    【讨论】:

      【解决方案3】:

      使用以下代码

      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();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-01
        • 2012-02-16
        • 1970-01-01
        • 2013-06-02
        • 1970-01-01
        • 2019-06-26
        • 2021-05-25
        相关资源
        最近更新 更多