在php页面中加载JpGraph
我想使用在php页面中加载JpGraph,php,jquery,ajax,jpgraph,Php,Jquery,Ajax,Jpgraph,我想使用ajax或javascript在另一个php页面中加载jpgraph。我在单独的php页面上成功地显示了图形,但我想显示从Graphs.php页面到index.php页面的图形。我试过了,但没有成功 index.php $('#submitG').click(function(e) { e.preventDefault(); // document.getElementById('content1').style.display = 'none'; alert("
ajax
或javascript
在另一个php
页面中加载jpgraph。我在单独的php页面上成功地显示了图形,但我想显示从Graphs.php
页面到index.php
页面的图形。我试过了,但没有成功
index.php
$('#submitG').click(function(e) {
e.preventDefault();
// document.getElementById('content1').style.display = 'none';
alert("gfh"+$('#startG').val()+$('#endG').val());
$('#cont').load('<img src="view.png">').fadeIn("slow");
alert("completed");
});
<form >
<input name="startG" type="date" id="startG" required/></div>
<input name="endG" type="date" id="endG" required/></div>
<input type="submit" value="Show Graph" id="submitG"/>
</form>
$('submitG')。单击(函数(e){
e、 预防默认值();
//document.getElementById('content1').style.display='none';
警报(“gfh”+$('#startG').val()+$('#endG').val());
$('#cont').load('').fadeIn(“慢”);
警报(“已完成”);
});
UPADTE:
//这是我要加载图像的div
<div id="cont"></div>
Graphs.php
<?php
include("DBConfig.php");
require_once ('/src/jpgraph.php');
require_once ('/src/jpgraph_line.php');
$ph1=array();
$ph2=array();
$ph3=array();
$sDate= $_POST['startDateG'];
$eDate=$_POST['endDateG'];
$datee1 = new DateTime($sDate);
$date1=$datee1->format('d-m-y'); // 31-07-2012
//echo " ";
$datee2 = new DateTime($eDate);
$date2=$datee2->format('d-m-y'); // 31-07-2012
if ($conn) {
//echo 'Connected';
$stid = oci_parse($conn, "SELECT * FROM table");
oci_execute($stid);
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
array_push($d1, $row['c1']);
array_push($d2, $row['c2']);
array_push($d3, $row['c3']);
}
}
$datay1 = array(20,15,23,15);
$datay2 = array(12,9,42,8);
$datay3 = array(5,17,32,24);
// Setup the graph
$graph = new Graph(1000,450);
$graph->SetScale("textlin");
$theme_class=new UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Single Pahse');
$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->SetLabelMargin(2);
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new LinePlot($d1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Line 1');
// Create the second line
$p2 = new LinePlot($d2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Line 2');
// Create the third line
$p3 = new LinePlot($d3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('Line 3');
$graph->legend->SetFrameWeight(1);
// Output line
$graph->Stroke();
oci_close($conn);
?>
尝试以下方法:
$('#submitG').click(function(e) {
e.preventDefault();
alert("gfh"+$('#startG').val()+$('#endG').val());
$('#cont').load(
'Graphs.php',
{
startG: $('#startG').val(),
endG: $('#endG').val(),
},
function() {
alert("completed");
$(this).fadeIn("slow"); // Or $('#cont').fadeIn("slow");
}
);
});
因为要通过
GET
获取数据,您必须在PHP
脚本中使用$\u GET['startDateG']
而不是$\u POST['startDateG']
。否则,您应该使用它的不显示图像及其显示数据,如:�巴布亚新几内亚IHDR���信息技术� IDATx���y\SW�8.�'�F�K٭��v���J�tt�:U������}�.3S_g�克格夫���西北�jw;v�kmm�P���V0aQ0 IȾ���P�$!���>��|���s����P|���硅�@B�卑诗省�J�B泰�#�B4`code>#cont是您的ìmg
标签吗?我在您问题的HTML
代码中找不到它。已解决:我在Graphs.php中使用了img标记,并将其加载到div中。谢谢您的帮助。我没有加载imag,而是加载字符串