我使用php JPgraph库为报告生成条形图。我想将报告导出到csv。为此我使用PHP将html写入csv。但图表不会导出到csv。它显示无法显示链接图像。没有物理图像。
report.php
<script src="js/customer_report.js"></script>
<div><a href="#" onclick="return htmlToExcel();" /></div>
<table><tr>
<td width="50%" colspan=5 >
<h2>Avg. by Day of Week</h2>
<img width="90%" height="500" align="center" src="../../dhr_reports_1.php" />
</div>
</tr></table>
dhr_reports_1.php
<?php
include('includes/includes.php');
require_once ('includes/classes/jpgraph/jpgraph.php');
require_once ('includes/classes/jpgraph/jpgraph_bar.php');
$id = $_SESSION['ad_account_adword_id'];
$endDate = date("Y-m-d", strtotime("-1 days"));
$startDate = date("Y-m-d", strtotime("-30 days"));
$sql = "SELECT ad_Date , SUM(ad_Clicks) ad_Clicks, SUM(ad_Conversions) ad_Conversions,ad_DayOfWeek ,
case when ad_DayOfWeek='Sunday' then 1
when ad_DayOfWeek='Monday' then 2
when ad_DayOfWeek='Tuesday' then 3
when ad_DayOfWeek='Wednesday' then 4
when ad_DayOfWeek='Thursday' then 5
when ad_DayOfWeek='Friday' then 6
else 7 end as day
FROM adword_campaign_reports where ad_Date BETWEEN '$startDate' AND '$endDate' and ad_account_id='$id' group by ad_DayOfWeek order by day; ";
$results = $main -> getResults($sql);
foreach($results as $result){
$date = $result->ad_DayOfWeek ;
$dataArray[] = $result->ad_Clicks ;
$dataArray1[] = $result->ad_Conversions ;
$datax[] = $date ;
}
$datazero=array(0,0,0,0);
$graph = new Graph(500,400);
$graph->title->Set('Avg. by Day of Week');
$graph->img->SetMargin(40,40,30,50);
// Setup Y and Y2 scales with some "grace"
$graph->SetScale("textlin");
$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(30);
$graph->y2axis->scale->SetGrace(30);
//$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('#0000ff','lightgray@0.5');
// Setup graph colors
$graph->SetMarginColor('gray');
$graph->y2axis->SetColor('#0000ff');
$graph->yaxis->SetColor('green');
// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datazero);
// Create the "Y" axis group
$ybplot1 = new BarPlot($dataArray);
//$ybplot1->value->Show();
$ybplot1->value->SetColor('green');
$ybplot1->SetFillColor('green');
$ybplot1->SetWidth(0.6);
$ybplot1->SetLegend("Clicks","green");
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));
// Create the "Y2" axis group
$ybplot2 = new BarPlot($dataArray1);
//$ybplot2->value->Show();
$ybplot2->value->SetColor('#0000ff');
$ybplot2->SetFillColor('#0000ff');
$ybplot2->SetWidth(0.6);
$ybplot2->SetLegend("Conversions","#0000ff");
$y2bplot = new GroupBarPlot(array($bplotzero,$ybplot2));
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
//$graph->xaxis->SetLabelAngle(50);
// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->AddY2($y2bplot);
// .. and finally stroke the image back to browser
$graph->Stroke();
?>
customer_report.js
function htmToExcel(){
var html = $("#summery_report_id").html();
$.post('servicefiles/html_excel.php',{html:html},function(data){
if(data==1){
$("#downloadHTML").css('display','none');
$("#downloadLink").css('display','');
window.open('phpHtmlExcel.php','_blank');
}
});
return false ;
}
html_excel.php
<?php
require_once dirname(__FILE__) . '/../../includes/includes.php';
$html=$_REQUEST['html'];
$_SESSION['html']=$html ;
echo 1;
?>
phpHtmlExcel.php
<?php
require_once dirname(__FILE__) . '/../includes/includes.php';
$file=phpHtmltoExcel.xls";
$test=$_SESSION['html'];
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file");
echo $test;
?>
图表未导入Excel工作表。如何将图表导入Excel。 ?