我正在使用jpgraph为我的网站绘制一些统计图表,我想这样做而不刷新页面。所以我将jpgraph代码放在一个单独的文件中,命名为plot_graphs.php并通过AJAX向它发送请求。现在,如果我直接打开文件plot_graphs.php,它会打开图表就好了。但是当我从AJAX打开它并指向它在页面上的<div>
中显示响应时,我得到的是:
�PNG IHDR,��� IDATx���i@���' I;Ⱦ���&*J]�ԥB�XEEK낈��Z۷�X�^�J�P�V��m�Ro]�V*R�Z��R�E�Av��S�Y&��ߧ0̜y�3'g&shb�BԡS]B��!�a��!�a��P}�ݻ7iҤ��
等等
有没有办法让这个工作没有重新加载页面并将plot_graphs.php代码直接放入div?如果重要,页面的字符集是utf-8。这些是plot_graphs.php的内容:
<?php
require_once ('../jpgraph/src/jpgraph.php');
require_once ('../jpgraph/src/jpgraph_line.php');
$type=$_GET['type'];
$unit=$_GET['unit'];
$term=$_GET['term'];
$datay1 = array(20,15,23,15);
$datay2 = array(12,9,42,8);
$datay3 = array(5,17,32,24);
// Setup the graph
$graph = new Graph(300,250);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Filled Y-grid');
$graph->SetBox(false);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('A','B','C','D'));
$graph->xgrid->SetColor('#E3E3E3');
/* $graph->SetBackgroundImage("tiger_bkg.png",BGIMG_FILLPLOT); */
// Create the first line
$p1 = new LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');
// Create the second line
$p2 = new LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Line 2');
// Create the third line
$p3 = new LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('Line 3');
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
?>
答案 0 :(得分:1)
看起来您正在尝试发送二进制数据而不指定数据是什么。试试这个:
header("Content-type: image/png");
$graph->Stroke();