English 中文(简体)
AJAX 以页面上的一堆符号显示的图像( 图形)
原标题:Image (graph) from AJAX displayed as a bunch of symbols on page

我使用 jpgraph 为我的网站绘制一些统计图表, 我想在不刷新页面的情况下这样做。 所以我将jpgraph 代码放在一个单独的文件中, 命名为proto_ graphs.php 并通过 AJAX 发送请求。 现在, 如果我直接打开文件绘图_ graphs.php, 它会打开图表。 但是当我从 AJAX 打开它, 并用它来显示页面上的 ; div> 中的答复时, 我得到的是:

PNG IHDR, IDATx i@ I;\\ & amp;* J} {B XEEEK} X J P V m Ro} V* R Z E Av S Y& 0y 3 g&shb BS} B!

是否有一种方法可以做到这一点, 而不重新加载页面, 直接将绘图_ graphs. php 代码直接放入 div 中? 页面的字符集是 utf-8, 如果重要的话 。 这些是 proph_ 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();

?>
最佳回答

看来你正在试图发送二进制数据, 但没有具体说明数据是什么。 尝试一下 :

header("Content-type: image/png");
$graph->Stroke();
问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...